更新时间:2023-11-30 13:54:52
人们使用是
是因为使用 ==
没有优势。可以编写比较等于 None
的对象,但不常见。
The reason people use is
is because there is no advantage to using ==
. It is possible to write objects that compare equal to None
, but it is uncommon.
class A(object):
def __eq__(self, other):
return True
print A() == None
输出:
True
是
不要认为这个事实很重要。
The is
operator is also faster, but I don't consider this fact important.