What truth value do objects evaluate to in Python?
Related Questions
Update: Removed all duplicate infomation with Meder's post
For custom objects in Python < 3.0 __nonzero__ to change how it is evaluated. In Python 3.0 this is __bool__ (Reference by e-satis)
It is important to understand what is meant by evaluate. One meaning is when an object is explicitly casting to a bool or implicitly cast by its location (in a if or while loop).
Another is == evalutation. 1==True, 0==False, nothing else is equal via ==.
>>> None==False
False
>>> 1==True
True
>>> 0==False
True
>>> 2==False
False
>>> 2==True
False
Finally, for is, only True or False are themselves.