Boolean priority? | Sololearn: Learn to code for FREE!

+1

Boolean priority?

Why is this output True? Does the Boolean “and” have a priority over “or”? What am I not understanding? print(True or True and False) Output: True How I attempted to solve was by taking it apart from left to right. True or True = (True) (True) and False = False End result is False. Which is what I thought.

5/6/2022 12:31:52 AM

Sal

2 Answers

New Answer

+4

As OP have not mentioned any language, I am assuming it to be python and if that's the case then Yes, logical AND have higher precedence than OR, meaning the expression would be evaluated like this print ( True or ( True and False )) Which will always result in True Check the following docs to know more about operator precedence in python👇 https://docs.python.org/3/reference/expressions.html#operator-precedence

+2

Yes, it was a python question! Thank you for the clarification.