Python中is和==的区别
2011-10-03 14:27
316 查看
通常我们写:
这个写法与以下的写法有何区别呢?
is当比较的是相同的对象实例时总是返回True。而==则完全决定于__eq__()方法的实现。例如:
if foo is None: pass
这个写法与以下的写法有何区别呢?
if foo == None: pass
is当比较的是相同的对象实例时总是返回True。而==则完全决定于__eq__()方法的实现。例如:
>>> class foo(object): def __eq__(self, other): return True >>> f = foo() >>> f == None True >>> f is None False
相关文章推荐
- python中is和 == 的区别
- python中is和 == 的区别
- Python is和==的区别
- Python中is和==的区别
- python中 is 和 == 的区别
- python 小知识点 "==" 与 "is"的区别
- python中==和is的区别,a==b和a is b
- Python中is和==的区别
- Python 中的None以及 == 与 is 的区别,以及判断某个list或者dict元素是否为None
- python题目-----is和==区别
- python中的is和==的区别
- python 的 is 与 == 区别
- Python中is和==的区别
- python判断语句is与==的区别
- Python is同一性运算符和==相等运算符区别
- Python学习之"is" 与 "==" 的区别详解
- Python的is和==区别(整理)
- Python自学之is和‘==’的区别
- Python判断语句中‘is’和‘==’的区别
- Python中is和==的区别