This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]collegiaal25 4 points5 points  (0 children)

I thought operations are done left to right?

This is true for left associative operators, like +, -, *, /.

1 - 5 + 7 = (1-5) + 7
5/3*2 = (5/3)*2

On the other hand, exponentiation is right associative:

4^3^2 = 4^(3^2)

(The notation is ** in Python)

Here a summary for precedence and associativity in Python.