0

I didn't understand operator precedence example in python. Can someone explain?

operator precedence example in python

27th Sep 2018, 3:16 PM
Ajay B
3 Respostas
+ 1
I think that you referring to table precedence. Imagine this expression: -2**4 How python resolve it? Raise to 4th power -2 or negate the result of 2 power 4? The answer is on that table and in this case interpreter raise 2 to 4 then negate the result because exponentation operator (**) has higher precendence with respect to negation operator (-). try to execute print(-2**4) and see
27th Sep 2018, 4:02 PM
KrOW
KrOW - avatar
0
False == False or True True >>> False == (False or True) False >>> (False == False) or True True Can u please explain this example?
27th Sep 2018, 4:11 PM
Ajay B
0
Well, comparison operators have HIGHER precendence on logical operators (like or) and grouping operator have higher precedence an all then: 1) False == False or True => True or True => True 2) False == (False or True) => False == True => False 3) (False == False) or True => True or True => True
27th Sep 2018, 4:25 PM
KrOW
KrOW - avatar