what exactly is "None" ?
"Martin v. Löwis"
martin at v.loewis.de
Tue Mar 4 11:51:10 EST 2003
More information about the Python-list mailing list
Tue Mar 4 11:51:10 EST 2003
- Previous message (by thread): what exactly is "None" ?
- Next message (by thread): what exactly is "None" ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
Regards,
Martin
- Previous message (by thread): what exactly is "None" ?
- Next message (by thread): what exactly is "None" ?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list