+ 1

Why does print(2**1**2) give me 2 in Python 3?

If I raise 2 to power of 1, it's still 2. Then raised to power of 2 it should give me 4. But I get 2.

11th Oct 2019, 12:34 PM
Michael Freeze
Michael Freeze - avatar
5 Respuestas
11th Oct 2019, 12:41 PM
Sousou
Sousou - avatar
+ 1
Hmm, that's interesting, but why doesn't it follow the usual left-to-right rule? Stacked exponentiation means multiplying the operands of power, which doesn't happen here
11th Oct 2019, 12:49 PM
Michael Freeze
Michael Freeze - avatar
+ 1
Михаил Морозов actually in math you also start from the upper power, unless there are parenthesis, same case here
11th Oct 2019, 1:18 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
Maybe only for power :/
11th Oct 2019, 12:53 PM
Sousou
Sousou - avatar
0
Checked for myself, can confirm you're right, Aymane.
11th Oct 2019, 4:29 PM
Michael Freeze
Michael Freeze - avatar