All values are considered “truthy” except for the following, which are “falsy”:
None
False
- Zeros, including:
0
0.0
0j
decimal.Decimal(0)
fraction.Fraction(0, 1)
- Empty sequences and collections, including:
[]
– an emptylist
{}
– an emptydict
()
– an emptytuple
''
– an emptystr
b''
– an emptybytes
set()
– an emptyset
- an empty
range
, likerange(0)
- objects for which
obj.__bool__()
returnsFalse
obj.__len__()
returns0
A “truthy” value will satisfy the check performed by if
or while
statements. We use “truthy” and “falsy” to differentiate from the bool
values True
and False
.
Truth Value Testing