There are a number of operations that are common to all data types. For example, all data types, and generally all objects, can be tested for a truth value in some way. The following are values that Python considers False
:
- The
None
type False
- An integer, float, or complex zero
- An empty sequence or mapping
- An instance of a user-defined class that defines a
__len__()
or__bool__()
method that returns zero orFalse
All other values are consideredTrue
.
A Boolean operation returns a value of either True
or False
. Boolean operations are ordered in priority, so if more than one Boolean operation occurs in an expression, the operation with the highest priority will occur first. The following table outlines the three Boolean operators in descending order of priority:
Operator | Example |
not | Returns |
| Returns |
| Returns |