bool(): Get Boolean Constant Function
1 Description
The Python bool
function will convert the supplied parameter
to a boolean type. There are two boolean types,
True
and
False
.
The bool
function will return True
for
any object passed to it. In order for the bool
function to return
False
you must pass one of the following
things to the bool
function.
- The constant None
- The constant
False
- The integer value zero:
0
- The float value zero:
0.0
- The numeric_j value zero:
0j
- The Decimal value zero:
Decimal(0)
- The Fraction value zero:
Fraction(0, 1)
- An empty string:
''
- An empty tuple:
()
- An empty list:
[]
- An empty dictionary:
{}
- An empty set:
set()
- An empty range:
range(0)
- An object which defines a
__bool__()
method which returnsFalse
when called - An object which defines a
__len__()
method which returns zero (0
) when called
This document was last updated: