← Python lessons

Numbers and Math

Part of a free Python course — sign up to save your progress and get AI hints.Sign up free

Two common Python number types are integers (whole numbers like 7) and floats (numbers like 3.75). Combine them with math operators.

Arithmetic operators

  • + add, - subtract, * multiply
  • / divide — always gives a float (10 / 2 is 5.0)
  • // floor divide — rounds the quotient down (7 // 2 is 3; -7 // 2 is -4)
  • % modulo — the remainder left over (7 % 2 is 1)
  • ** power (2 ** 3 is 8)
print(10 + 3)print(10 / 3)print(10 // 3)print(10 % 3)

Division always makes a float

Even when it divides evenly, / produces a decimal number:

print(6 / 3)

That prints 2.0, not 2. For integers and floats, / gives a float — worth remembering when your answer has an unexpected .0 on the end.

Rounding

round(value, n) rounds a number to n decimal places:

average = 37 / 3print(average)print(round(average, 2))

Order of operations

Python follows normal maths order — * and / happen before + and -. Use parentheses when you want a different order:

print(2 + 3 * 4)print((2 + 3) * 4)

See also: Variables.

Your turn

Add two lines: print a floor-divided by b, then print the remainder of a divided by b.

🎯 Goal — make it print exactly:
3
2
a = 17b = 5# add two prints: floor division first, then the remainder