Return a Boolean value, either True or False.
The bool class is a subclass of int. It converts a value to a Boolean using the standard truth testing procedure. If the value is omitted or false, it returns False; otherwise it returns True.
The bool class has only two instances: True and False. These are the only Boolean values in Python. When converting values, the following are considered false: None, False, zero of any numeric type, empty sequences, and empty mappings.
Custom objects can define their truth value by implementing the __bool__() method. If __bool__() is not defined, __len__() is consulted, and the object is considered true if its length is nonzero.
| Name | Description | Optional |
|---|---|---|
x |
A value to convert to a Boolean. | Yes |
bool(0) # Returns False
bool(1) # Returns True
bool([]) # Returns False