By default, instances of user-defined classes are considered truthy, unless either __bool__
or __len__
is implemented.
bool(x)
calls x.__bool__()
and uses the result. If __bool__
is not implemented, Python tries to invoke x.__len__()
, and if that returns zero, bool
returns False
. Otherwise bool
returns True
.
__bool__
must return a Boolean.