Returns an expression converted into a Boolean.
- Required. If expression is False or omitted, this returns False; otherwise it returns True.
bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.
The following values are interpreted as false:
- numeric zero of all types
- empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets)
All other values are interpreted as true. (See the __nonzero__() special method for a way to change this.)
>>> bool(1) True >>> bool(0) False >>> bool("False") True >>> bool([0, 0]) True >>> bool() False >>> bool(2+2) True