Python Booleans Cheat Sheet

>>> bool(None)
False
>>> bool(False)
False
>>> bool(0)
False
>>> bool(1)
True
>>> bool(0.0)
False
>>> bool(0.01)
True
>>> bool(0j)
False
>>> bool(0.1j)
True
>>> from fractions import Fraction
>>> bool(Fraction(0, 1))
False
>>> bool(Fraction(1, 2))
True
>>> from decimal import Decimal
>>> bool(Decimal(0.0))
False
>>> bool(Decimal(0.1))
True
>>> bool('')
False
>>> bool('False')
True
>>> bool(())
False
>>> bool(('False'))
True
>>> bool([])
False
>>> bool(['False'])
True
>>> bool({})
False
>>> bool({'False': True})
True
>>> bool(set())
False
>>> bool(set('False'))
True
>>> bool(range(0))
False
>>> bool(range(1))
True
>>> class TypicalClass:
...     def __main__(self):
...             pass
...
>>> bool(TypicalClass())
True
>>> class FalseClass:
...     def __bool__(self):
...             return False
...
>>> bool(FalseClass())
False
>>>
>>> class LenZeroClass:
...     def __len__(self):
...             return 0
...
>>> bool(LenZeroClass())
False
>>>
>>> class LenZeroButTrue:
...     def __len__(self):
...             return 0
...     def __bool__(self):
...             return True
...
>>> bool(LenZeroButTrue())
True
>>> class NotLenZeroButFalse:
...     def __len__(self):
...             return 100
...     def __bool__(self):
...             return False
...
>>> bool(NotLenZeroButFalse())
False