True inconsistency in Python

Terry Reedy tjreedy at udel.edu
Tue Nov 18 00:41:28 EST 2003


"Jimmy Retzlaff" <jimmy at retzlaff.com> wrote in message
news:mailman.811.1069099332.702.python-list at python.org...

>the singleton False has exactly one value (as does the
>singleton True

Reworded: NoneType is a singleton type whose singleton instance has
value None and is initially bound to the name None.  bool is a
doubleton type whose two and only two instances have values True and
False and are initially bound to the names True and False.

> Comparing a value directly to False in Python is not a good idea.

Unless that is exactly what you want to do.

> So, for example, the following two "if" statements are not
equivalent
> for all possible values of x:

> if not x:
> if x == False:

Which is why one might possibly want the second, except that it can be
written for faster execution (because the False object is unique) as

if x is False:

Terry J. Reedy






More information about the Python-list mailing list