-1
print(6 and 0 or 5==9 and 4 and '7' or 0 and 8)
print(4 or 8 and 56==0 or 5 and 0 or 5 and 'hoe' or 0 and 'f')

what is the order of computation of multiple logical operators in python? is it sequentially from either side?

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378

1 Answers1

0

It follows the precedence order as defined in operator precedence.

In short, NOT > AND > OR.

Your code translates to:

(6 and 0) or (5==9 and 4 and '7') or (0 and 8)
(4) or (8 and 56==0) or (5 and 0) or (5 and 'hoe') or (0 and 'f')
jfaccioni
  • 7,099
  • 1
  • 9
  • 25