0

Which operator takes precedence in 4 > 5 or 3 < 4 and 9 > 8? Would this be evaluated to true or false?

I know that the statement 3 > 4 or (2 < 3 and 9 > 10) should obviously evaluate to false but I am not quite sure how python would read 4 > 5 or 3 < 4 and 9 > 8

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
M. dike
  • 1
  • 1

1 Answers1

2

Comparisons are executed before and, which in turn comes before or. You can look up the precedence of each operator in the expressions documentation.

So your expression is parsed as:

(4 > 5) or ((3 < 4) and (9 > 8))

Which comes down to:

False or (True and True)

which is True.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343