-4

(8 == 8) or (8 == 9) and (8 == 6) Out[24]: True

(9 == 0) or (8 == 8) and (7 == 9) Out[25]: False

i expected to be the same boolean output which is both false because the computer will evaluate expression from left to the right.

Thank You!

  • 1
    Why would you expect the same output? Do you understand the evaluation oder between `and` and `or`? The computer does **NOT** evaluate "from left to right". – luk2302 Aug 09 '23 at 08:19
  • "the computer will evaluate expression from left to the right." Just no. – Julien Aug 09 '23 at 08:19
  • 2nd option will be `False or True and False`... `False or False`... `False` 1st option will be `True or False and False`.. .`True or False`... `True`.. – Talha Tayyab Aug 09 '23 at 08:19
  • It's a matter of [*operator precedence*](https://docs.python.org/3/reference/expressions.html#operator-precedence). E.g. `(8 == 8) or (8 == 9) and (8 == 6)` is really parsed as `(8 == 8) or ((8 == 9) and (8 == 6))`. – Some programmer dude Aug 09 '23 at 08:27

0 Answers0