Order of Operations

Code follows the same precedence you learned in math: exponents, then multiplication/division, then addition/subtraction. Parentheses override everything. When in doubt, add parentheses, clarity is free.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Write an expression that adds 2 and 3, then multiplies the result by 4, so it prints 20. You'll need parentheses.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Floats, Rounding, and Honest Money Math →
← Back