object
没有实现__eq__
,因此回退到默认比较id(x) == id(y)
,即 它们是同一对象实例 (x is y
)吗?
每次调用都会创建一个新实例object()
,my_object
它将永远不会*等于除自身以外的任何值。
这适用于2.x和3.x:
# 3.4.0
>>> object().__eq__(object())
NotImplemented
# 2.7.6
>>> object().__eq__(object())
Traceback (most recent call last):
File "<pyshell#60>", line 1, in <module>
object().__eq__(object())
AttributeError: 'object' object has no attribute '__eq__'