From the Python 5.1 documentation:
Any object can be checked for true, for use in an if or while condition, or as an operand of the following Boolean operations. The following values ββare considered false:
- None
- False
- zero of any number type, for example,
0 , 0L , 0.0 , 0j . - any empty sequence, for example
'' , () , [] . - any empty mapping, for example
{} . - instances of user-defined classes if the class defines the
__nonzero__() or __len__() method when this method returns the integer 0 or the value bool False.
Why? Because it is convenient when iterating through objects, looping, checking if a value is empty, etc. In general, it adds some parameters to how you write code.
source share