~ Numbers


Order of operations

Python's order of operations works just like math's:

  1. Parentheses
  2. Exponents
  3. Multiplication and division
  4. Addition and subtraction

You've already seen this, actually. The challenge problems at the end of the exponent section asked for these three calculations in a console:

16 ** 0.5
16 ** (1/2)
16 ** 1/2

The first two raise 16 to the 0.5 power – they take the square root of 16. The second problem first raises 16 to the first power (returning 16) and then divides that by 2, leaving 8.

In programming, just like in math, order of operations matter!