is None or == None ?

Stefan Behnel stefan_ml at
Fri Nov 6 14:33:14 CET 2009

mk, 06.11.2009 14:20:
> Some claim that one should test for None using:
> if x is None:

Which is the correct and safe way of doing it.

> ..but the standard equality which is theoretically safer works as well:
> if x == None:

Absolutely not safe, think of

   class Test(object):
       def __eq__(self, other):
           return other == None

   print Test() == None, Test() is None


More information about the Python-list mailing list