SythraOpen app

Order of Operations in Python

Python evaluates expressions using operator precedence — the same PEMDAS idea as math: parentheses first, then **, then * / // %, then + -. When operators tie, Python usually goes left to right.

Sythra

7 min read

XLinkedIn
Order of Operations in Python — cover illustration

Want to understand the order of operations in Python? You write 2 * 3 - 1 and expect 5 — but only if Python evaluates multiplication before subtraction. Python does not read left to right blindly; it follows a fixed operator precedence rulebook (the same idea as PEMDAS in math).

This page maps that hierarchy: parentheses, exponentiation, multiplication/division, addition/subtraction — plus what happens when operators tie. Pair it with Operators and Operands in Python for the full operator families, and Statements vs Expressions for how expressions produce values.

What you will learn

By the end you can:

  • Explain operator precedence / PEMDAS in Python
  • Predict how Python evaluates mixed expressions like 2 ** 1 + 1
  • Know that * and / share a level (left to right)
  • Use parentheses to force intent — not just fix bugs, but aid readers
  • Spot the classic degrees / 2 * pi grouping trap

We are not covering bitwise precedence, chained comparisons, or every edge case in the language reference. This page is the everyday math-expression mental model beginners need.

The rulebook Python follows

Python does not invent its own math order. It follows the same hierarchy you learned in school, often remembered as PEMDAS (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction). To Python it is not a mnemonic — it is strict precedence.

Priority (high → low)OperatorsNotes
1( )Parentheses — always first
2**Exponentiation
3* / // %Multiply, divide, floor-divide, modulo — same level
4+ -Addition and subtraction — last

When two operators share the same level, Python evaluates left to right (except **, which is right-associative — a detail you rarely need at first).

Parentheses — the highest authority

Whenever Python sees parentheses, it evaluates the inside first:

print(2 * (3 - 1))
# inside: 3 - 1 → 2
# then:    2 * 2 → 4

Another example with exponents:

print((1 + 1) ** (5 - 2))
# (1 + 1) → 2
# (5 - 2) → 3
# 2 ** 3  → 8

Parentheses do not only change results — they make intention clear. Even when not required:

(minute * 100) / 60  # same math, easier to read

Exponentiation — before multiplication

Powers happen before multiply/add:

print(2 ** 1 + 1)
# 2 ** 1 → 2
# 2 + 1  → 3   (not 2 ** 2 = 4)

If you wanted 2 ** (1 + 1), you must say so with parentheses.

Multiplication and division — equal priority

*, /, //, and % sit on the same precedence level — stronger than + and -, but not above ** or ( ).

print(2 * 3 - 1)
# 2 * 3 → 6
# 6 - 1 → 5

When priority ties — left to right

Same-level operators evaluate left to right. This matters for division and multiplication chained together:

degrees = 180
pi = 3.14159

# Python reads this as (degrees / 2) * pi
result = degrees / 2 * pi

If you meant degrees / (2 * pi), you must write the parentheses explicitly:

result = degrees / (2 * pi)

Common mistakes

  • Assuming strict left-to-right for all operators
  • Forgetting that / and * tie — grouping matters
  • Expecting 2 ** 1 + 1 to equal 4
  • Skipping parentheses when intent is unclear
  • Mixing up PEMDAS with “everything left to right”

When the result surprises you

Python is not guessing or being clever — it is being consistent. If the result surprises you, it is usually precedence, not a broken interpreter. When in doubt: write what you mean. Use parentheses.

Common questions

What is the order of operations in Python?

Python follows operator precedence similar to PEMDAS: parentheses first, then exponentiation (**), then multiplication/division/modulo, then addition and subtraction. When operators have equal precedence, evaluation is generally left to right.

Does Python follow PEMDAS?

Yes, for the arithmetic operators beginners use most. Parentheses come first, then **, then * / // %, then + -. Python's full precedence table has more operators, but the PEMDAS core matches school math.

What is operator precedence in Python?

Operator precedence is the rule that decides which operation runs first in an expression without parentheses. Higher-precedence operators bind tighter — for example, * happens before +.

Why is 2 * 3 - 1 equal to 5 in Python?

Multiplication has higher precedence than subtraction. Python computes 2 * 3 = 6 first, then 6 - 1 = 5.

Does multiplication come before division in Python?

No — * and / have the same precedence level. When they appear together, Python evaluates left to right. So a / b * c is (a / b) * c unless parentheses say otherwise.

Should I use parentheses in Python expressions?

Use parentheses whenever they make your intent clearer — even if Python would parse the expression correctly without them. Clear code beats clever code.

Explore

Related topics

Keep going — these sit next to this concept in a real learning path.

Browse all python explainers →