
Python arithmetic operators are the building blocks of any calculation you write in code. Whether you are totaling a shopping cart, splitting a bill, or computing a physics formula, these operators handle the math. Python makes this especially clean because it supports seven distinct arithmetic operators right out of the box, each designed for a specific kind of numeric operation.
This guide walks through every Python arithmetic operator one by one. For each one you will see what it does, why it exists, a self-contained code example you can run immediately, and a clear explanation of the output.
Python gives you these arithmetic operators:
| Operator | Symbol | Example |
|---|---|---|
| Addition | + | 5 + 3 |
| Subtraction | - | 5 - 3 |
| Multiplication | * | 5 * 3 |
| Division | / | 5 / 3 |
| Floor Division | // | 5 // 3 |
| Modulo | % | 5 % 3 |
| Exponentiation | ** | 5 ** 3 |
Each one returns a number, but the type — int or float — depends on the operator and the operands involved. Understanding that distinction is key to avoiding subtle bugs.
The addition operator combines two numbers together. It works with integers, floats, and even mixes of the two. When you add an integer to a float, Python automatically promotes the result to a float so no precision is lost.
# Python addition operator examples
whole_price = 45
discount = 5.50
tax = 3.25
subtotal = whole_price - discount
total = subtotal + tax
print("Subtotal:", subtotal)
print("Total after tax:", total)
print("Type of total:", type(total))
Subtotal: 39.5
Total after tax: 42.75
Type of total: <class 'float'>
Notice that even though the original price was a plain integer, mixing it with floats in the expression caused Python to return floats automatically. This is called implicit type promotion and it means you rarely need to cast types manually in arithmetic.
The subtraction operator removes one value from another. It behaves symmetrically with addition: integers stay integers unless a float is involved, and negative results are perfectly valid.
# Subtraction with positive and negative results
altitude_start = 3200
altitude_end = 890
descent = altitude_start - altitude_end
below_sea = 100 - 450 # goes negative
print("Descent in meters:", descent)
print("Below reference point:", below_sea)
Descent in meters: 2310
Below reference point: -350
Subtraction is used constantly in countdown timers, measuring differences between timestamps, tracking inventory, and computing deltas in data analysis.
The multiplication operator scales a value. In Python, the symbol is * rather than the traditional × to avoid conflict with variable names. Multiplying two integers gives an integer; multiplying with a float gives a float.
# Multiplication operator in Python
hourly_rate = 18.50
hours_worked = 40
overtime_hours = 6
overtime_multiplier = 1.5
regular_pay = hourly_rate * hours_worked
overtime_pay = hourly_rate * overtime_multiplier * overtime_hours
gross_pay = regular_pay + overtime_pay
print(f"Regular pay: ${regular_pay:.2f}")
print(f"Overtime pay: ${overtime_pay:.2f}")
print(f"Gross pay: ${gross_pay:.2f}")
Regular pay: $740.00
Overtime pay: $166.50
Gross pay: $906.50
The :.2f inside the f-string formats the float to two decimal places, which is exactly what you want when displaying currency.
Division in Python always returns a float, even when both operands are integers and the division is exact. This changed in Python 3 — in Python 2, dividing two integers performed floor division by default. If you are reading older code, watch out for that difference.
# Python division always returns float
apples = 10
baskets = 5
per_basket = apples / baskets
half = 7 / 2
print("Apples per basket:", per_basket)
print("Type:", type(per_basket))
print("Half of 7:", half)
print("Type:", type(half))
Apples per basket: 2.0
Type: <class 'float'>
Half of 7: 3.5
Type: <class 'float'>
Even though 10 divided by 5 is a whole number, Python still gives you 2.0 as a float. This consistent behavior prevents a whole category of bugs where you expect a decimal result but get a truncated integer.
Floor division uses the // operator and rounds the result down to the nearest integer — toward negative infinity, not toward zero. This distinction matters for negative numbers.
Floor division is essential when you need to know how many complete groups fit into something: how many full weeks in a given number of days, how many complete pages to print, how many whole boxes you can fill.
# Floor division examples including negative numbers
total_days = 100
days_per_week = 7
full_weeks = total_days // days_per_week
remaining_days = total_days % days_per_week # using modulo, explained next
print("Full weeks:", full_weeks)
print("Remaining days:", remaining_days)
# Floor division with negatives rounds toward negative infinity
print("\nFloor division with negatives:")
print(7 // 2) # 3
print(-7 // 2) # -4, not -3 — rounds DOWN
print(7 // -2) # -4
Full weeks: 14
Remaining days: 2
Floor division with negatives:
3
-4
-4
The negative number behavior surprises many beginners. -7 // 2 gives -4 instead of -3 because floor division always rounds toward negative infinity, not toward zero. If you need truncation toward zero, use int(-7 / 2) instead.
The modulo operator % returns the remainder after division. It answers the question: after dividing as many whole times as possible, what is left over? This operator is far more useful than it might first appear.
Common uses include checking whether a number is even or odd, cycling through a list repeatedly, calculating time in hours and minutes, and implementing circular buffers.
# Python modulo operator practical examples
seconds_total = 7384
hours = seconds_total // 3600
remaining = seconds_total % 3600
minutes = remaining // 60
seconds = remaining % 60
print(f"Time: {hours}h {minutes}m {seconds}s")
# Check even/odd
for number in [14, 27, 100, 333]:
if number % 2 == 0:
print(f"{number} is even")
else:
print(f"{number} is odd")
Time: 2h 3m 4s
7384 seconds equals exactly 2 hours, 3 minutes, and 4 seconds.
14 is even
27 is odd
100 is even
333 is odd
The time conversion example shows how floor division and modulo work as a pair. Floor division extracts the whole part; modulo extracts the leftover. Together they let you break any quantity into components.
The exponentiation operator ** raises the left operand to the power of the right operand. Python has this built into the language itself, so you do not need to import the math module just to compute powers.
This operator is right-associative, meaning 2 ** 3 ** 2 evaluates as 2 ** (3 ** 2), which is 2 ** 9 = 512, not (2 ** 3) ** 2 = 64. That is the standard mathematical convention, but it is worth knowing explicitly.
# Python exponentiation operator
# Compound interest formula: A = P(1 + r/n)^(nt)
principal = 1000.0
annual_rate = 0.06 # 6%
compounds_per_year = 12 # monthly
years = 5
amount = principal * (1 + annual_rate / compounds_per_year) ** (compounds_per_year * years)
interest_earned = amount - principal
print(f"Principal: ${principal:.2f}")
print(f"After {years} years: ${amount:.2f}")
print(f"Interest earned: ${interest_earned:.2f}")
# Powers of 2 (common in computing)
print("\nPowers of 2:")
for exp in range(8):
print(f"2 ** {exp} = {2 ** exp}")
Principal: $1000.00
After 5 years: $1348.85
Interest earned: $348.85
Powers of 2:
2 ** 0 = 1
2 ** 1 = 2
2 ** 2 = 4
2 ** 3 = 8
2 ** 4 = 16
2 ** 5 = 32
2 ** 6 = 64
2 ** 7 = 128
You can also use fractional exponents to compute roots. 16 ** 0.5 is the square root of 16 (which is 4.0), and 27 ** (1/3) is the cube root of 27 (which is 3.0).
When multiple arithmetic operators appear in a single expression, Python follows a specific order of evaluation. This order is often remembered using the acronym PEMDAS: Parentheses, Exponentiation, Multiplication/Division/Floor Division/Modulo, then Addition/Subtraction.
Operators at the same precedence level are evaluated left to right, except for exponentiation which is right to left.
# Python operator precedence examples
result1 = 2 + 3 * 4 # multiplication first: 2 + 12 = 14
result2 = (2 + 3) * 4 # parentheses first: 5 * 4 = 20
result3 = 2 ** 3 ** 2 # right-to-left: 2 ** 9 = 512
result4 = 10 - 4 / 2 + 1 # division first: 10 - 2.0 + 1 = 9.0
result5 = 17 % 5 + 3 * 2 # 2 + 6 = 8
print("2 + 3 * 4 =", result1)
print("(2 + 3) * 4 =", result2)
print("2 ** 3 ** 2 =", result3)
print("10 - 4 / 2 + 1 =", result4)
print("17 % 5 + 3 * 2 =", result5)
2 + 3 * 4 = 14
(2 + 3) * 4 = 20
2 ** 3 ** 2 = 512
10 - 4 / 2 + 1 = 9.0
17 % 5 + 3 * 2 = 8
When in doubt, add parentheses. They cost nothing in performance but make your intent unmistakable to anyone reading the code, including your future self.
Python also provides shorthand forms that combine an arithmetic operator with assignment. These are called augmented assignment operators and they modify a variable in place without having to repeat the variable name.
# Augmented assignment operators in Python
score = 100
score += 50 # same as: score = score + 50
print("After += 50:", score)
score -= 30 # same as: score = score - 30
print("After -= 30:", score)
score *= 2 # same as: score = score * 2
print("After *= 2:", score)
score //= 3 # same as: score = score // 3
print("After //= 3:", score)
score **= 2 # same as: score = score ** 2
print("After **= 2:", score)
score %= 50 # same as: score = score % 50
print("After %= 50:", score)
After += 50: 150
After -= 30: 120
After *= 2: 240
After //= 3: 80
After **= 2: 6400
After %= 50: 0
These shorthands are especially common in loops where you accumulate a total, count items, or step through a range with a custom increment.
Python's numeric type system does what you would expect: if any operand in an arithmetic expression is a float, the result is a float. The only exception is the floor division and modulo operators, which can return integers if both operands are integers.
# Integer vs float results
print(type(3 + 4)) # int
print(type(3 + 4.0)) # float
print(type(10 / 2)) # float — always
print(type(10 // 2)) # int — both operands are int
print(type(10.0 // 2)) # float — one operand is float
print(type(10 % 3)) # int
print(type(10.0 % 3)) # float
<class 'int'>
<class 'float'>
<class 'float'>
<class 'int'>
<class 'float'>
<class 'int'>
<class 'float'>
Knowing which type each operator returns matters when passing values to functions that expect a specific type, or when comparing results where 2 and 2.0 look the same but behave differently in type checks.
This example builds a simple invoice calculator that uses every Python arithmetic operator in a realistic context.
# Invoice calculator using all Python arithmetic operators
def calculate_invoice(unit_price, quantity, discount_pct, tax_rate):
# Multiplication: line total
gross_total = unit_price * quantity
# Subtraction + multiplication: apply percentage discount
discount_amount = gross_total * (discount_pct / 100)
after_discount = gross_total - discount_amount
# Multiplication: compute tax
tax_amount = after_discount * (tax_rate / 100)
# Addition: final total
invoice_total = after_discount + tax_amount
# Floor division + modulo: split into dollars and cents
dollars = int(invoice_total)
cents = round((invoice_total - dollars) * 100)
# Exponentiation: show what this total grows to if invested at 5% for 3 years
future_value = invoice_total * (1 + 0.05) ** 3
return {
"gross_total": gross_total,
"discount_amount": discount_amount,
"after_discount": after_discount,
"tax_amount": tax_amount,
"invoice_total": invoice_total,
"dollars": dollars,
"cents": cents,
"future_value": future_value,
}
result = calculate_invoice(
unit_price=49.99,
quantity=7,
discount_pct=10,
tax_rate=8.5,
)
print("======= INVOICE SUMMARY =======")
print(f"Gross total: ${result['gross_total']:.2f}")
print(f"Discount (10%): -${result['discount_amount']:.2f}")
print(f"After discount: ${result['after_discount']:.2f}")
print(f"Tax (8.5%): +${result['tax_amount']:.2f}")
print(f"Invoice total: ${result['invoice_total']:.2f}")
print(f" = ${result['dollars']} and {result['cents']} cents")
print(f"\nIf invested at 5%/yr for 3 years: ${result['future_value']:.2f}")
======= INVOICE SUMMARY =======
Gross total: $349.93
Discount (10%): -$34.99
After discount: $314.94
Tax (8.5%): +$26.77
Invoice total: $341.71
= $341 and 71 cents
If invested at 5%/yr for 3 years: $395.44
Every operator in this example serves a clear purpose: multiplication for totals, subtraction and addition for adjusting the running amount, division inside the percentage calculations, floor division and modulo for splitting the total into whole dollars and cents, and exponentiation for the compound growth projection. That is exactly how Python arithmetic operators appear in real applications — not in isolation, but woven together to solve a practical problem.
For the official language reference on numeric types and operators, see the Python documentation on numeric types and the operator precedence table.