Vladimir

1%
Flag icon
By default, instances of user-defined classes are considered truthy, unless either __bool__ or __len__ is implemented. Basically, 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.
Fluent Python: Clear, Concise, and Effective Programming
Rate this book
Clear rating
Open Preview