Arithmetic Operators
An overview of Python's seven arithmetic operators: addition, subtraction, multiplication, division, floor division, modulo, and exponentiation.
Arithmetic Operators
Addition (+), Subtraction (-), Multiplication (*)
These three work exactly as in mathematics:
Division (/)
In Python, / always returns a float, even if both numbers are integers and the result is whole:
Floor Division (//)
If you need integer division — the whole part only, fractional part discarded — use //:
The name "floor division" comes from the mathematical floor function — floor(x) means rounding down to the nearest integer on the number line. For positive numbers this feels natural: floor(3.75) = 3. But for negative numbers it may surprise you:
Mathematically, -7 / 2 = -3.5. The floor of -3.5 on the number line is -4, because -4 is the nearest integer that is less than or equal to -3.5.
Modulo (%)
The modulo operator returns the remainder after division:
You will use % constantly in competitive programming — for checking if a number is even or odd, for cyclic indexing, and for keeping numbers within a range:
Exponentiation (**)
Python has a built-in operator for raising a number to a power:
Operator Precedence
When an expression contains multiple operators, Python evaluates them in a specific order — just like in mathematics. From highest to lowest priority:
| Priority | Operator | Description |
|---|---|---|
| 1 | ** | Exponentiation |
| 2 | , , , |