Truth Values
suggest changeThe following values are considered falsey, in that they evaluate to False in a boolean context.
- None
- False
0, or any numeric value equivalent to zero, such as0.0or0j- Empty sequences:
'',"",(),[] - Empty mappings:
{} - Empty sets:
set(),frozenset() - User-defined types where
__bool__returnsFalse, or where__len__returns0when__bool__is absent
__bool__ must return a bool. Returning 0 from it raises TypeError.
All other values in Python evaluate to True.
Note: A common mistake is to simply check for the Falseness of an operation which returns different Falsey values where the difference matters. For example, using if foo() rather than the more explicit if foo() is None
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents