The following values are all false in Python programming language.
- None
- False
- numbers equal to 0: 0, 0L, 0.0, 0j
- empty sequences:e.g., ‘””, (), [], array.array(‘i’)
- empty maps: e.g., {}
- any object that defines a __nonzero__ or __len__ method (returning False or len=0, respectively
This is a Thing that is Wrong with Python.
(The Right Way: false is None or False; everything else is true.)
(Note: I really do disagree with this design decision, but I’m mostly writing this down so I will remember not to write code like this:
if object.table: print 'table was initialized'
but instead remember to write:
if object.table and len(object.table)>0: print 'table was initialized'