Operators

Module 2 · Operators · Lesson 3 of 4

Operators and their priorities

When several operators meet in one expression, Python doesn't just work left to right — it follows precedence, a ranking that decides which operation happens first. It's the same “multiplication before addition” rule you learned in school.

Not left to right — by priority
2 + 3 * 4
2 + 12
2 + 12
14

* outranks +, so it goes first — even though it's written second.

From highest priority to lowest, the arithmetic operators rank like this:

  1. ** — exponentiation
  2. unary + and - (sign)
  3. *, /, //, %
  4. binary + and -

Operators on the same level run left to right — with one famous exception. ** goes right to left, so 2 ** 2 ** 3 is 2 ** 8 = 256, not 4 ** 3.

Run it yourselfruns in your browser · Python
main.py

You don't have to memorise the whole ladder. When in doubt — or just to make your intent obvious — wrap the part you want done first in parentheses. They always win, and they make code easier to read. That wraps up the operators; next, a quick quiz.