Questions about Python ** (multiple-squares operator)

Asked 2 years ago, Updated 2 years ago, 19 views

print(3 ** 3 ** 3)
print(27 ** 3)

print(3**3**3) is output as 7625597484987 print(27**3) is output 19683.

I thought of the code print (3 ** 3 ** 3) as the cube of three, the cube of 27 The price is too high. Why is it coming out like this?

python

2022-09-20 10:53

1 Answers

Due to operator priority,

This is because it was calculated as 3 ** (3**3) = 3**27. It's good to memorize operator priorities accurately, but field developers use parentheses to clarify code for these ambiguities.


2022-09-20 10:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.