Truth Values
suggest changeThe following values are considered falsey, in that they evaluate to False
when applied to a boolean operator.
- None
- False
0
, or any numerical value equivalent to zero, for example0L
,0.0
,0j
- Empty sequences:
''
,""
,()
,[]
- Empty mappings:
{}
- User-defined types where the
__bool__
or__len__
methods return 0 orFalse
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