- The empty string, the empty list, the empty dictionary, the empty set, and zero all evaluate to False.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
bool('') # the empty string Out[1]: False bool('a non-empty string') # a non-emepty string Out[2]: True bool(list()) # the empty list Out[3]: False bool(['a non-empty list']) # a non-empty list Out[4]: True bool(dict()) # the empty dictionary Out[5]: False bool({'key':'value'}) # a non-empty dictionary Out[6]: True bool(set()) # the empty set Out[7]: False bool({'a non-empty set'}) # a non-empty set Out[8]: True bool(0) # zero Out[9]: False bool(1) # a non-zero Out[10]: True |