python's or and and do not return Boolean types, even though they are Boolean operators
>>> True and False
False
>>> 0 or 1
1
or x or y Returns x if x is True Returns y if x is False
and x and y Returns y if x is True Returns x if x is False
So connect a lot
>>> 0 and 1 or 1 or 0 and 1
1
>>> 0 and 1 or (1 or 0) and 1
1
>>> 0 and (1 or 1) or 0 and 1
0
Or play Evaluation is done in order from the front after putting in parentheses
>>> ((((0 and 1) or 1) or 0) and 1)
1
>>> (((0 and 1) or (1 or 0)) and 1)
1
>>> (((0 and (1 or 1)) or 0) and 1)
0
Same as
Recommended Posts