Python - Booleans evaluation order | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Python - Booleans evaluation order

print(1 or 0 and 0) outputs 1. Is it correct to say that, with no parentheses, Python evaluates boolean expressions right-to-left?

30th May 2019, 5:10 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 Answers
+ 5
No, it's not correct. Boolean AND has higher precedence than boolean OR. https://docs.python.org/3/reference/expressions.html#operator-precedence
30th May 2019, 5:14 PM
Diego
Diego - avatar
+ 3
Paolo De Nictolis hi, First 0 and 0 get evaluated which becomes 0 then (1 or 0) remains which evaluated 1 or 0 is evaluate and gives 1 so output comes as 1 Have some 🍎 🍎 🍎 🍎 🍎
30th May 2019, 5:19 PM
DishaAhuja
DishaAhuja - avatar
+ 2
And if my conclusion is correct, why does print(1 or 0 and 0) outputs 1?
30th May 2019, 5:14 PM
Paolo De Nictolis
Paolo De Nictolis - avatar