In Chapter 2, Simple Data Types, we introduced the None
object. It is a unique, immutable object, often used to indicate that a parameter should have a default value or that an input is not available. Some languages have a special null object or null pointer that have similar semantics to the Python None
object.
The None
object has no arithmetic operators defined. It's equivalent to False
. The ==
and !=
operators are generally defined for None
. However, these operators aren't always appropriate because other objects might exhibit similar behavior.
Generally, we'll use the is
comparison when trying to determine if a variable is set to None
. The ==
test can be redefined by a class that implements the __eq__
special method; the is
test cannot be overridden.
Since bool(None) == False
, we can use a variable which may be None
in an if
condition. Nevertheless, we should generally use is None
or is...