Python Arithmetic
Addition
Adding in Python is very simple. To add numbers, we just put a plus (+
) in between them.
Subtraction
Subtraction is the same as addition, but now using a dash (-
).
Multiplication
Multiplication is also the same as addition, but using an asterisk (*
).
Division
Adding in Python is very simple. To add numbers, we just put a slash (/
) in between them.
Getting the Remainder
Let's say that we want to know the remainder of a รท b. In Python, we stick a percent symbol between a and b. So, a % b
. In programming, this operation is called modulus.
Floor Division
Here, "floor" means "rouding down". This is basically like not doing the decimals in long division. Instead of using /
, here we use //
.
Exponents
Exponents are easy. If we wanted to do ab, we would write it as a ** b
in Python.