且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中为None

更新时间: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.