What is the order of operations in Python?

In Python, operations has a specific order. This will affect how a program runs and what expressions are processed first.

Subscribe to my newsletter and never miss my upcoming articles

Python's order of operations is the same as that of normal mathematics:

  • Parentheses first ()
  • Then exponentiation **
  • Then multiplication * and division /
  • And then addition + and subtraction -

This is why the following operation:

x = 7
y = 5 
z = 6

print(x + y * z) 

## Output: 37

Would have a different output than this one:

x = 7
y = 5 
z = 6

print((x + y) * z) 

## Output: 72