PythonArithmetic Operators

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

3 + 2

5

-

Subtraction

3 - 2

1

*

Multiplication

3 * 2

6

/

True division

7 / 2

3.5

//

Floor division

7 // 2

3

%

Modulo (remainder)

7 % 2

1

**

Exponentiation

2 ** 5

32

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

Python
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
This changed between Python 2 and 3
In Python 2, `/` between two ints performed floor division by default (unless you imported `division` from `__future__`). Python 3 made `/` always mean true division, and introduced `//` as the explicit floor-division operator. If you see old code where `5 / 2` seems to expect `2`, it was written for Python 2.
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

Python
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
Why this matters
If you're porting code from C, Java, or JavaScript, don't assume `%` behaves the same way — in those languages, `-7 % 3` evaluates to `-1` (sign follows the dividend). Python's convention is actually more mathematically consistent for things like wrapping indices or angles, because the result of `a % b` is always in the range `[0, b)` when `b` is positive.
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.

Python
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.

Tip
When debugging unexpected division results, print `type(result)` alongside the value. A stray `float` where you expected an `int` (or vice versa) is one of the most common sources of subtle bugs in numeric Python code.