Arithmetic Operators
tip
Now that you've learned how to write and execute your own Python code, try out the things you've learned in this section by yourself.
Practice makes perfect!
Knowing how to perform simple arithmetic to your variables in Python is going to be a vital part of almost any code that you are writing.
Here are the Arithmetic Operators
Operation | Syntax | Description | Example (+ output) |
---|---|---|---|
Addition | a + b | Adds a and b together | 1 + 1 = 2 |
Subtraction | a - b | Subtracts b from a | 3 - 2 = 1 |
Multiplication | a * b | Multiplies a and b | 72 * 2 = 142 |
Division | a / b | Divides a and b | 17 / 4 = 4.25 |
Integer Division | a // b | Divides a and b , rounded down | 17 // 4 = 4 |
Exponentiation | a ** b | Raises a to the power of b | 2 ** 4 = 16 |
Modulus | a % b | Produces a modulo b a % b produces the remainder of dividing a by b | 17 % 4 = 1 |