Python Boolean: Difference between revisions
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
=Operators= | =Operators= | ||
==OR: <tt>|</tt> and <tt>|=</tt>== | ==OR: <tt>|</tt> and <tt>|=</tt>== | ||
<syntaxhighlight lang='py'> | |||
assert (True | True) | |||
assert (True | False) | |||
assert (False | True) | |||
assert not (False | False) | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='py'> | |||
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 | |||
</syntaxhighlight> | |||
Note that <code>+</code> applied to booleans contest to integers. |
Revision as of 19:44, 15 April 2022
Internal
Overview
x = True
type(x)
<class 'bool'>
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.