Before we dive into Python, let's start with the operators used in Python.
Addition
>>> 1 + 2
Try writing the above and pressing enter. Do you get an answer?
Subtraction
>>> 50 - 4 46
Multiplication
>>> 12345678 * 3 37037034
Computers know that * means multiply. What about division?
division
/ is division.
>>> 5000 / 3 1666.6666666666667 >>> 5000 // 3 1666
Remainder
To get the remainder, use the % operator. For example, the remainder of 50 divided by 8 is ?
>>> 50 % 8 2
The quotient of 50 divided by 8 is 6 and the remainder is 2, so the result of 50% 8 is 2.
Finding the quotient and remainder at once
>>> divmod(50, 8) (6, 2)
You can also use the divmod() function to calculate the quotient and remainder at once, like this