Arithmetic Operators
Arithmetic operators are used with numeric values to perform common mathematical operations:
| Operator | Name | Example | Try it |
|---|---|---|---|
| + | Addition | x + y | |
| - | Subtraction | x - y | |
| * | Multiplication | x * y | |
| / | Division | x / y | |
| % | Modulus | x % y | |
| ** | Exponentiation | x ** y | |
| // | Floor division | x // y |
Examples
Here is an example using different arithmetic operators:
Example
x = 15
y = 4
print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
print(x ** y)
print(x // y)
Division in Python
Python has two division operators:
- / - Division (returns a float)
- // - Floor division (returns an integer)
Example
x = 12
y = 5
print(x / y)
Example
x = 12
y = 5
print(x // y)