Python has seven arithmetic operators. Four of them work as on a calculator; the other three are worth learning early.
The program
python
a = 15 b = 4 print("a + b =", a + b) print("a - b =", a - b) print("a * b =", a * b) print("a / b =", a / b) print("a // b =", a // b) print("a % b =", a % b) print("a ** b =", a ** b)
output
a + b = 19 a - b = 11 a * b = 60 a / b = 3.75 a // b = 3 a % b = 3 a ** b = 50625
How it works
/is normal division. It always gives a float, even when the answer is whole:8 / 2is4.0.//is floor division: it divides and rounds down to a whole number. 15 divided by 4 is 3.75, which rounds down to 3.%gives the remainder after division: 4 goes into 15 three times (12), and 3 is left over.**raises to a power: 15 to the power 4 is 15 × 15 × 15 × 15 = 50625.
// and % are used together a lot. For example, 135 minutes is 135 // 60 hours and 135 % 60 minutes: 2 hours and 15 minutes.