Python Boolean: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 2: Line 2:
* [[Python_Language#Boolean|Python Language]]
* [[Python_Language#Boolean|Python Language]]
=Overview=
=Overview=
A boolean can be <code>True</code> or <code>False</code>.
<syntaxhighlight lang='python'>
<syntaxhighlight lang='python'>
x = True
x = True
Line 7: Line 8:
<class 'bool'>
<class 'bool'>
</syntaxhighlight>
</syntaxhighlight>
=Operators=
=Operators=
==OR: <tt>|</tt> and <tt>|=</tt>==
==OR: <tt>|</tt> and <tt>|=</tt>==

Revision as of 03:58, 18 June 2022

Internal

Overview

A boolean can be True or False.

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.