- 20

Print(2**3**2).?

answer is 512 ...?how it is 512..?

8th Apr 2017, 5:51 AM
eddula naresh
eddula naresh - avatar
10 odpowiedzi
+ 8
Left to right precedence is fine. But there are other rules also, such as 2 pow (3 pow 2) You cannot calculate power of 2 until 3 pow 2 evaluates to a number. So, it needs to be evaluated first.
8th Apr 2017, 6:34 AM
Ashwani Kumar
Ashwani Kumar - avatar
+ 11
2**3**2 2 pow (3 pow 2) 2 pow 9 512
8th Apr 2017, 6:07 AM
Ashwani Kumar
Ashwani Kumar - avatar
+ 4
bit confused there @Vega 8**2 is 64 what happenens in the print is as follows: let's define two events, a and b a is 3**2 b is 2**a b a 2**(3**2) a is evaluated first to give us 3 to the power of 2 and returns 9 a=3**2=9 then b is evaluated as 2 to the power of a ro give us 2 to the power of 9 which returns as 512 b=2**9=512
8th Apr 2017, 6:09 AM
Burey
Burey - avatar
+ 4
"Operators in the same box group left to right (except for exponentiation, which groups from right to left)." https://docs.python.org/3/reference/expressions.html#operator-precedence That means, a**b**c evaluates to a**(b**c).
8th Apr 2017, 6:35 AM
Álvaro
+ 2
try writing it like this (2**3)**2 and see what happens ;)
8th Apr 2017, 6:34 AM
Burey
Burey - avatar
+ 1
we have to done from left to Right..this operation.right..?then y we take first 3**2
8th Apr 2017, 6:31 AM
eddula naresh
eddula naresh - avatar
0
very helpful. Thank you
22nd Mar 2022, 6:01 AM
Samuel Mugo
0
2*3**3*4???
18th May 2022, 5:55 PM
Santosh Maurya
0
What is the output of the following? * x = 36/4* (3 + 2) * 4+2 print(x)
29th Sep 2023, 5:16 AM
Marco Brian Tejones
Marco Brian Tejones - avatar
- 7
help with the output print( (3**2)//2 )
16th Feb 2021, 7:51 AM
lucy wangu
lucy wangu - avatar