+ 2

Python operator precedence

So I tried in the playground and got this: print((True == False) or True) and the output is True. As I see it, this statement equals this: print(False or True) and the output is True. Does this mean True has a higher precedence than False? If not, what’s the explanation? Also are “print((True == False) or True)” and “print(True == False or True)” the same since == has a higher precedence than or? Thanks in advance!

12th Nov 2018, 2:46 PM
Lauren
1 ответ
0
True is not operator! "True == False or True" is equal to "(True == False) or True" because == has higher precedence than or. True or False do not change the precedence of operators
12th Nov 2018, 3:16 PM
portpass