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
Output:
True
The is
operator is also faster, but I don't consider this fact important.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…