Arithmetic Operators
Arithmetic operators do the math: addition, subtraction, multiplication, and three different flavors of division, plus exponentiation. Python's arithmetic looks familiar if you've used any C-like language, but a couple of the details — especially true division versus floor division, and how the modulo operator behaves with negative numbers — are different enough to catch people off guard.
The operators at a glance
Operator | Name | Example | Result |
|---|---|---|---|
| Addition |
|
|
| Subtraction |
|
|
| Multiplication |
|
|
| True division |
|
|
| Floor division |
|
|
| Modulo (remainder) |
|
|
| Exponentiation |
|
|
True division vs. floor division
This is the single most important thing to know about Python 3 arithmetic: / always returns a float, even when both operands are integers and divide evenly. If you want integer-style division that rounds toward negative infinity, use // instead.
True division always returns a float
print(10 / 2) # 5.0 -- float, even though it divides evenly print(7 / 2) # 3.5 print(type(10 / 2)) # <class 'float'> print(10 // 2) # 5 -- int, because both operands were ints print(7 // 2) # 3 -- rounds toward negative infinity print(type(10 // 2)) # <class 'int'> # Floor division with a float operand still returns a float: print(7.0 // 2) # 3.0
Modulo with negative numbers
The % operator returns the remainder of division, but Python defines that remainder differently than C, Java, or JavaScript do. In Python, the result of % always has the same sign as the divisor (the right-hand operand) — not the same sign as the dividend, which is what C-family languages do.
The sign of the divisor wins
print(7 % 3) # 1 -- straightforward print(-7 % 3) # 2 -- NOT -1! Result takes the sign of the divisor (3) print(7 % -3) # -2 -- takes the sign of the divisor (-3) print(-7 % -3) # -1 # This is consistent with floor division: # a % b is always equal to a - (a // b) * b print(-7 - (-7 // 3) * 3) # -7 - (-3 * 3) = -7 + 9 = 2
1 2 -2 -1 2
Exponentiation
** raises the left operand to the power of the right operand. It also accepts negative and fractional exponents, which gives you reciprocals and roots for free.
print(2 ** 10) # 1024 print(2 ** -1) # 0.5 -- negative exponent gives a float print(9 ** 0.5) # 3.0 -- fractional exponent gives a square root print((-8) ** (1/3)) # not exactly -2.0 due to floating-point/complex quirks
A quick word on precedence
Arithmetic operators don't all bind equally tightly. ** binds tighter than unary minus on its left side, and both ** and unary minus bind tighter than *, /, //, and %, which in turn bind tighter than + and -. That's why 2 + 3 * 4 is 14, not 20, and -2 ** 2 is -4 (the ** applies before the negation). This section only scratches the surface — the dedicated operator precedence page covers the full table across every operator family, including how arithmetic interacts with comparisons and boolean logic.
A preview of augmented assignment
Python also offers shorthand combining an arithmetic operator with assignment, such as x += 1 instead of x = x + 1. There are augmented forms for every arithmetic operator (+= -= *= /= //= %= **=). This page won't go deep on them — the assignment operators page covers all the augmented forms, including how they interact with mutable objects like lists.