Python Boolean: Difference between revisions
Jump to navigation
Jump to search
Tag: Reverted |
Tags: Manual revert Reverted |
||
Line 48: | Line 48: | ||
Note that <code>+</code> applied to booleans contest to integers. | Note that <code>+</code> applied to booleans contest to integers. | ||
Revision as of 19:56, 16 May 2024
Internal
Overview
A boolean can be True
or False
.
x = True
type(x)
<class 'bool'>
What is True?
The following values evaluate to False
in Python. Everything else evaluates to True
.
- boolean
False
None
- zero integer
0
- zero float
0.0
- empty string
- empty list
[]
- empty tuple
()
- empty dict
{}
- empty set
set()
Operators
OR: | and |=
assert (True | True)
assert (True or True)
assert (True | False)
assert (True or False)
assert (False | True)
assert (False or True)
assert not (False | False)
assert not (False or False)
l = [True, False]
b = False
for e in l:
b |= e
assert b
l = [False, False]
b = False
for e in l:
b |= e
assert not b
Note that +
applied to booleans contest to integers.