Python Boolean: Difference between revisions
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=What is True?= | =What is True?= | ||
The following values evaluate to <code>False</code> in Python. Everything else evaluates to <code>True</code> | The following values evaluate to <code>False</code> in Python. Everything else evaluates to <code>True</code>. | ||
* boolean <code>False</code> | * boolean <code>False</code> | ||
* <code>None</code> | * <code>None</code> |
Revision as of 20:05, 19 June 2022
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 | False)
assert (False | True)
assert not (False | 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.