tags:

views:

79

answers:

2

How do I refer to the null object in Python?

+8  A: 

In Python, the 'null' object is the singleton None.

The best way to check things for "Noneness" is to use the identity operator, is:

if foo is None:
    ...
Ben James
And the reason for choosing `egg is None` over `egg == None`: The latter can be overloaded, and is likely to break when comparing valid object with None (depends on how it's implemented, but you don't expect everyone to take comparisions with None into account, do you?), while `is` always works the same.
delnan
+1  A: 

It's not called null as in other languages, but None. There is always only one instance of this object, so you can check for equivalence with x is None (identity comparison) instead of x == None, if you want.

AndiDog