Prev: random & math modules | Next: Print
Booleans are implemented in Python as a subclass of integer, having only two values ("instance objects"): True and False
A boolean obect can be constructed by: (a) assigning True or False to a name, or (b) calling the bool([x]) constructor
a = False
type(a)
x = 0
b = bool(x)
b, type(b)
a = 5
b = bool(a > 0)
b
- None
- False
- zero of any numeric type, for example, 0, 0.0, 0j.
- Empty sequence (for example, empty list [ ], or empty string ' ')
- Empty mapping (for example, empty dictionary { })
< less than
<= less than or equal
> strictly greater than
>= greater than or equal
== equal
!= not equal
is object identity
is not negated object identity
a = 0
b = 0.0
c = []
d = [0]
e = ''
a == 0, b != 0, c <= [1], d is not False, e is ''
x = True
y = False
x and y, x or y, not x
x = y = True
a = b = False
(x or a) or (y and b)
. Free learning material
. See full copyright and disclaimer notice