Playground / Order of Operations

Evaluate it one step at a time

Order of Operations

Interactive lab

Try it: Order of Operations

How Python decides which operator in an expression runs first — precedence, left-to-right order and right-to-left **, plus what /, // and % really return.

How it works

  1. Parentheses first; then **, which groups right to left and binds tighter than a minus sign on its left.
  2. Then *, /, // and %, left to right; then + and −, left to right.
  3. / always gives a float; // rounds down; % takes the sign of the divisor.
  4. Each step replaces one operation with its value until one number is left.

Default run (7 steps): Expression: 2 + 3 * (7 - 4) ** 2 // 5. Python evaluates left to right, but higher-precedence operators bind first. … Result: 7 (an int).

Simplified: Numbers (at most 6 digits) and arithmetic operators only; parsed and evaluated by the lab's own evaluator (no eval), checked against real Python results.

Educational simulation

Loading the simulation…