identity versus equality for None in Python

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.

Leave a Comment