---
title: Order of Operations in Python
source: https://app.sythra.ai/learn/python/order-of-operations
topic: Python
updated: 2026-08-12
publisher: Sythra (https://app.sythra.ai)
---

# 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.

_Source: [https://app.sythra.ai/learn/python/order-of-operations](https://app.sythra.ai/learn/python/order-of-operations) — free to read on Sythra._

## Key points

- PEMDAS / operator precedence decides what runs first
- Parentheses override everything
- ** runs before * and /
- * and / share a level — evaluated left to right
- degrees / 2 * pi means (degrees / 2) * pi unless you parenthesize
- Add parentheses for humans, not only for the machine

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](/learn/python/operators-operands) for the full operator families, and [Statements vs Expressions](/learn/python/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) | Operators | Notes |
| --- | --- | --- |
| 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:

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

Another example with exponents:

```python
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:

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

## Exponentiation — before multiplication

Powers happen before multiply/add:

```python
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 `( )`.

```python
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:

```python
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:

```python
result = degrees / (2 * pi)
```

> **Programmer habit:** 

## 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.**

> **Practice with Sythra:**  [Practice with AI tutor](https://app.sythra.ai/pricing)

## FAQ

### 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.

## Related

- [Operators and Operands in Python](https://app.sythra.ai/learn/python/operators-operands) — The operator families precedence builds on.
- [Statements vs Expressions in Python](https://app.sythra.ai/learn/python/statements-vs-expressions) — Expressions produce values — precedence decides how.
- [Variables in Python](https://app.sythra.ai/learn/python/variables) — Names like degrees and pi in grouped expressions.
- [Types, Values, and Errors in Python](https://app.sythra.ai/learn/python/types-values-errors) — int, float, and the values operators combine.
- [Data Types in Python](https://app.sythra.ai/learn/python/data-types) — int, float, str, bool, list, tuple, dict, set — the full map.
- [Interactive Mode vs Script Mode in Python](https://app.sythra.ai/learn/python/interactive-mode-vs-script-mode) — Why the same line of code behaves differently in each mode.
- [Python course hub](https://app.sythra.ai/learn/python) — All free Python explainers and the path into Agentic practice.

---

Written by Sythra — Learn machine learning by building. Practice this topic with Sythra's AI tutor: https://app.sythra.ai/pricing
