Almost every calculation you write in Python comes down to a small handful of symbols: +, -, *, and a few others. These are Python's arithmetic operators, and while the basics are simple, a few of them behave in ways that catch beginners off guard — particularly division and how negative numbers interact with it. This article covers all seven, plus the precedence rules that determine how they combine.
What Are Arithmetic Operators?
An operator is a symbol that performs an operation on values, called operands. In 5 + 3, the + is the operator, and 5 and 3 are the operands.
Python has seven core arithmetic operators:
Operator | Operation |
|---|---|
| Addition |
| Subtraction |
| Multiplication |
| True division |
| Floor division |
| Modulo (remainder) |
| Exponentiation |
Python fully supports mixed arithmetic — combining an int and a float in the same expression works without any special handling, as covered in the earlier article on type conversion:
result = 5 + 2.5
print(result) # 7.5The rest of this article walks through each operator, including a couple that behave a little differently than you might expect.
The Core Operators: Addition, Subtraction, Multiplication
Straightforward numeric use
print(5 + 3) # 8 — addition
print(5 - 3) # 2 — subtraction
print(5 * 3) # 15 — multiplication
Bonus behavior: strings
Two of these python operators do something unexpected — but genuinely useful — when applied to strings instead of numbers.
+ concatenates strings together:
greeting = "Hello, " + "World!"
print(greeting) # Hello, World!* repeats a string a given number of times:
line = "-" * 20
print(line) # --------------------That second one is a handy shortcut for building separator lines or simple visual formatting without a loop.
Common pitfall: mixing strings and numbers
Trying to use + between a string and a number directly raises an error, since Python won't guess whether you meant to combine them as text or convert one of them first:
age = 30
print("Age: " + age)
# TypeError: can only concatenate str (not "int") to strThe fix is explicit conversion, using str():
print("Age: " + str(age)) # Age: 30
(Or, as covered in the strings article earlier in this series, an f-string sidesteps this entirely: f"Age: {age}".)
Division Operators: True Division vs. Floor Division
This is where Python's arithmetic gets a little more interesting — and where floor division vs division confusion trips up a lot of beginners.
True division (/)
The / operator always returns a float, even when the division happens to come out evenly:
print(10 / 2) # 5.0 — note the .0, even though it divides evenly
print(10 / 3) # 3.3333333333333335Floor division (//)
The // operator, by contrast, discards any remainder and returns the whole number part — but specifically by rounding toward negative infinity, not simply "toward zero" or "down" in the way you might assume.
print(10 // 3) # 3 — straightforward with positive numbersHere's the surprise: with negative numbers, floor division doesn't behave the way most beginners expect.
print(-10 // 3) # -4, not -3Mathematically, -10 / 3 is approximately -3.33. Floor division rounds down to the nearest whole number — meaning toward negative infinity — so it lands on -4, not -3. If you're expecting truncation toward zero (the way int() behaves), this will catch you off guard the first time you hit it.
Modulo (%)
The % operator returns the remainder of a division:
print(10 % 3) # 1 — 10 divided by 3 is 3 remainder 1
print(7 % 2) # 1 — 7 is odd
print(8 % 2) # 0 — 8 is evenThat last example points to modulo's most common practical use: checking whether a number is even or odd.
number = 15
if number % 2 == 0:
print("Even")
else:
print("Odd")It's also useful for wrapping values within a range — for example, cycling through a fixed set of options, or converting a total number of seconds into minutes and leftover seconds.
Exponentiation and Operator Precedence
The python exponent operator
** raises a number to a power:
print(2 ** 3) # 8 — 2 to the power of 3
print(5 ** 2) # 25 — 5 squared
print(9 ** 0.5) # 3.0 — fractional exponents work too, this is a square rootA common syntax mistake: writing 2 * * 3 with a space between the asterisks. Python won't understand this as exponentiation — it needs to be written as a single, unspaced ** token.
Operator precedence (PEMDAS in Python)
When an expression combines multiple operators, Python evaluates them in a specific order, closely mirroring the PEMDAS rule taught in math class:
Parentheses — evaluated first, always
Exponents (
**)Multiplication, division, floor division, modulo (
*,/,//,%) — evaluated left to rightAddition, subtraction (
+,-) — evaluated left to right
Walking through an example
result = 2 + 3 * 4 ** 2 - 6 / 2Step by step:
4 ** 2→16(exponent first)3 * 16→48(multiplication)6 / 2→3.0(division)2 + 48 - 3.0→47.0(addition/subtraction, left to right)
print(result) # 47.0When precedence gets hard to track mentally, parentheses are your friend — grouping parts of an expression explicitly makes the intended order obvious to anyone reading the code, including future you.
Common Arithmetic Errors and How to Avoid Them
TypeError from incompatible types
Covered above, but worth restating as a general rule: combining a string and a number with an arithmetic operator (outside of the specific +/* string behaviors) raises a TypeError. The fix is always the same — convert explicitly with int(), float(), or str() as appropriate before the operation.
ZeroDivisionError
Dividing by zero — with either / or // — raises an error rather than returning something like infinity:
print(10 / 0)
# ZeroDivisionError: division by zeroIf there's any chance a divisor could legitimately be zero (a user-supplied value, a calculated denominator that might come out to zero), guard against it explicitly:
numerator = 10
denominator = 0
if denominator != 0:
print(numerator / denominator)
else:
print("Cannot divide by zero")Real-world example: calculating a discounted price
Putting several of these operators together in a practical scenario:
original_price = 80.00
discount_percent = 25
discount_amount = original_price * (discount_percent / 100)
final_price = original_price - discount_amount
print(f"You save: ")
print(f"Final price: ")
# You save: $20.00
# Final price: $60.00This small example touches division (converting a percentage to a decimal), multiplication (calculating the discount), and subtraction (applying it) — a fairly typical mix of what everyday arithmetic in Python actually looks like once you move past isolated examples.