what exactly is "None" ?

"Martin v. Löwis" martin at v.loewis.de
Tue Mar 4 17:51:10 CET 2003

Andrei Doicin wrote:
> I know that "None" is the Boolean false value that
> gets thrown out when there's nothing to return or a
> function doesn't manage to reach the end of itself and thus "return
> whatever",

This is only partially correct: Even though None is a boolean false 
value, it is not *the* boolean false value (i.e. it is not the canonical 
representative). Other false values are 0, 0.0, "", [], and {}. In 
Python 2.3, the canonical false value is False.

> but *what* (in Python terms) exactly is equal to "None" ???

Please distinguish "equality" and "identity". Objects can declare 
themselves equal (==) to None, by, say, implementing __eq__. However, 
only None is identical (is) to itself: None is the singleton instance of 
the NoneType, there are no other objects like None (and you cannot 
create new instances of the NoneType).

More precisely, None is a builtin name (a key in __builtins__) that is 
bound to this singleton instance.

> I ask this as I'm trying to set up some conditional statements that do
> something if "whatever" is equal to "None".

The canonical expressions for that is "whatever is None". It is both 
faster and more correct than checking for equality.


More information about the Python-list mailing list