+ 1

The expression 2**2**3 is evaluated as: (2**2)**3? True or False

answer is : False But this is True, as much as i know, if two operators have same precedence the the left one evaluate first. eg: 5%4*2 --> (5%4)*2 --> (1)*2 ---> 2 not 5%(4*2) ---> 5%8 ---> 5

24th Sep 2021, 6:14 PM
Jitendra
Jitendra - avatar
3 Answers
+ 2
Most operators are indeed left associative, but ** is right associative, mainly because (a**b)**c == a**(b*c) While a**(b**c) doesn't have an easy identity Just like we don't see a*b+c as a*(b+c) == (a*b) + (a*c), but as (a*b) + c
25th Sep 2021, 12:17 PM
Angelo
Angelo - avatar
+ 3
I think, it is False also. Cause, 2**2**3 = 2^2^3 = 2^8 = 256 (2**2)**3 = (2^2)^3 = 4^3 = 64 You see the result of this expressions and these are not equal. So, the answer is False. I hope, it's clear. Happy coding!
24th Sep 2021, 6:19 PM
mesarthim
mesarthim - avatar
+ 3
operator precedence for ** is from right to left in your case . You can google "operator precedence in python" and go through the offical docs for info.
24th Sep 2021, 6:44 PM
Abhay
Abhay - avatar