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
2010-07-20 11:54:27
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
2010-07-20 12:25:01