Python Arithmetic Operators
Arithmetic Operators
Arithmetic operators are used with numeric values to perform common mathematical operations:
Operator | Name | Example | Try it |
---|---|---|---|
+ | Addition | x + y | Try it » |
- | Subtraction | x - y | Try it » |
* | Multiplication | x * y | Try it » |
/ | Division | x / y | Try it » |
% | Modulus | x % y | Try it » |
** | Exponentiation | x ** y | Try it » |
// | Floor division | x // y | Try it » |
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)
Try it Yourself »
Division in Python
Python has two division operators:
- / - Division (returns a float)
- // - Floor division (returns an integer)
Example
Floor division always returns an integer.
It rounds DOWN to the nearest integer:
x = 12
y = 5
print(x // y)
Try it Yourself »