Skip to content

Python Arithmetic Operators

Updated 6 min read Aimerscrew

Adding up a shopping cart, splitting a dinner bill, working out how many hours are in 200 minutes: all of this is arithmetic, and Python arithmetic operators let your programs do it in one short line. In this lesson, you'll learn all seven of them, what type of result each one gives, and some clever everyday uses for the two that confuse beginners most: // and %.

🌍 Real-life example

Four friends order 3 pizzas, and each pizza is cut into 8 slices. That's 3 * 8 = 24 slices. How many does each person get? 24 // 4 = 6. Any slices left over? 24 % 4 = 0. Multiply, floor-divide, remainder: three arithmetic operators answered the whole dinner question.

What are arithmetic operators in Python?

An operator is a symbol that performs an action on values. The values it works on are called operands. In 7 + 2, the operator is + and the operands are 7 and 2. Arithmetic operators are the operators that do math.

OperatorNameExampleResult
+Addition10 + 313
-Subtraction10 - 37
*Multiplication10 * 330
/Division10 / 33.3333333333333335
//Floor division10 // 33
%Modulo (remainder)10 % 31
**Exponent (power)10 ** 31000

Here they are in a real program that totals a small grocery order:

apples = 4
apple_price = 0.5
bread = 2.25

total = apples * apple_price + bread
print(total)

budget = 10
print(budget - total)
4.25
5.75

What type of result does each operator give?

The type of the answer matters, because an int (whole number) and a float (decimal number) print and behave differently. You saw a preview of this in Python numbers; here are the rules in one place:

  • +, -, *, //, % and ** give an int when both operands are ints.
  • If either operand is a float, the result is a float.
  • / always gives a float, even when the division is exact.
print(12 / 4)
print(12 // 4)
print(12.0 // 4)
print(5 * 2.0)
print(2 ** 10)
print(2 ** -1)
3.0
3
3.0
10.0
1024
0.5

Notice the last line: a negative exponent means "one divided by", so 2 ** -1 is 1 / 2, which is a float.

📝 Note

+ and * also work on text. "ice" + "cream" joins two strings into "icecream", and "ha" * 3 repeats one into "hahaha". You'll see more of this in Python strings.

How does floor division (//) work?

Floor division divides and then rounds the answer down to the nearest whole number. "Floor" is the math word for rounding down, like stepping down to the floor below.

guests = 23
seats_per_table = 6

full_tables = guests // seats_per_table
print(full_tables)
3

23 guests fill 3 tables completely (18 people), so // gives 3.

Floor division with negative numbers

This catches many people out. "Round down" means toward negative infinity, not toward zero. For a negative answer, rounding down makes the number more negative:

print(7 // 2)
print(-7 // 2)
print(int(-7 / 2))
3
-4
-3

-7 / 2 is -3.5. Rounding down goes to -4. By contrast, int() just chops off the decimal part, giving -3. They agree for positive numbers but not for negative ones.

How does the modulo operator (%) work?

The modulo operator % gives the remainder after division: what's left over once you've made as many full groups as possible. // and % are a pair: one tells you how many full groups, the other tells you the leftovers.

Animation: 17 items are packed into boxes of 5. Three full boxes are filled, so 17 // 5 is 3, and 2 items are left over, so 17 % 5 is 2
Pack 17 items into boxes of 5: // counts the full boxes, % counts the leftovers.
print(17 // 5)
print(17 % 5)
print(3 * 5 + 2)
3
2
17

The last line shows the rule that always holds: (a // b) * b + (a % b) gives back a.

Use 1: Is a number even or odd?

An even number divided by 2 leaves no remainder. So number % 2 is 0 for even numbers and 1 for odd ones:

print(14 % 2 == 0)
print(9 % 2 == 0)
True
False

(The == operator checks whether two values are equal. You'll learn it properly in comparison operators.)

Use 2: Wrap-around, like a clock

A 24-hour clock goes back to 0 after 23. Modulo does that wrap-around for you. If a flight leaves at 22:00 and takes 5 hours, when does it land?

departure_hour = 22
flight_hours = 5

arrival_hour = (departure_hour + flight_hours) % 24
print(arrival_hour)
3

22 + 5 is 27, and 27 % 24 is 3, so the plane lands at 3:00 the next morning. The same trick works for days of the week (% 7) or a playlist that loops back to the first song.

Use 3: Converting minutes to hours and minutes

movie_minutes = 152

hours = movie_minutes // 60
minutes = movie_minutes % 60
print(hours, "h", minutes, "min")
2 h 32 min

💡 Tip

Need both answers at once? The built-in divmod() function returns the floor division and the remainder together: divmod(152, 60) gives (2, 32).

How does the exponent operator (**) work?

** raises a number to a power: base ** exponent. It's handy for squares, cubes and growth over time. Here's how $1,000 grows in a savings account paying 5% a year for 3 years:

savings = 1000
rate = 0.05
years = 3

final = savings * (1 + rate) ** years
print(round(final, 2))
print(9 ** 0.5)
1157.63
3.0

Raising to the power of 0.5 gives a square root, so 9 ** 0.5 is 3.0.

Real-world example: splitting a restaurant bill

Let's put several operators together. Five friends share a $137 bill and add an 18% tip. Each person pays a whole number of dollars, and we want to know how much extra goes into the tip jar:

bill = 137
tip_percent = 18
people = 5

total = bill + bill * tip_percent / 100
print("Total with tip:", total)

each_pays = total // people + 1      # round up to whole dollars
print("Each person pays:", each_pays)

collected = each_pays * people
print("Extra for the tip jar:", round(collected - total, 2))
Total with tip: 161.66
Each person pays: 33.0
Extra for the tip jar: 3.34

Because total is a float, total // people is a float too (32.0), so we get 33.0. You could wrap it in int() to print 33.

Common mistakes with arithmetic operators

1. Dividing by zero

slices = 8
people = 0
print(slices / people)
ZeroDivisionError: division by zero

The same error happens with // and %. Make sure the right-hand side can never be zero.

2. Expecting / to give a whole number

10 / 2 is 5.0, not 5. If you need an int, use // (or int() when you know the division is exact).

3. Using ^ for powers

print(2 ^ 3)
print(2 ** 3)
1
8

In many calculators ^ means "power", but in Python it's a completely different operator (bitwise XOR). Always use **.

4. Adding a number to text

age = "30"
print(age + 1)
TypeError: can only concatenate str (not "int") to str

Values from input() are always text. Convert them first with int() or float(), as you learned in type conversion.

Practice exercise

🏋️ Try it yourself

A warehouse has 250 water bottles. They are packed into crates of 24. Write a program that prints how many full crates there are, how many bottles are left over, and whether the number of full crates is even (True or False).

Show solution
bottles = 250
crate_size = 24

full_crates = bottles // crate_size
left_over = bottles % crate_size

print("Full crates:", full_crates)
print("Left over:", left_over)
print("Even number of crates:", full_crates % 2 == 0)
Full crates: 10
Left over: 10
Even number of crates: True

What's next?

You can now do math in Python. Next, learn the shortcuts for updating a variable with math, like score += 10, in Python assignment operators.

Key takeaways

  • Python has seven arithmetic operators: +, -, *, /, //, % and **.
  • The / operator always returns a float, even for exact divisions like 10 / 2.
  • If either operand is a float, the result of +, -, *, // and % is a float too.
  • Floor division // rounds down toward negative infinity, so -7 // 2 is -4.
  • Modulo % gives the remainder; use it for even/odd checks, clock-style wrap-around and unit conversions.
  • Use ** for powers, never ^, which is a different operator in Python.

Frequently asked questions

What is the difference between / and // in Python?

The / operator does normal division and always returns a float, so 7 / 2 is 3.5. The // operator does floor division and rounds down to a whole number, so 7 // 2 is 3.

What does % mean in Python?

The % operator is modulo. It returns the remainder after division, so 17 % 5 is 2, because 5 goes into 17 three times with 2 left over.

How do you check if a number is even in Python?

Use the modulo operator: number % 2 == 0 is True for even numbers and False for odd numbers.

Why is -7 // 2 equal to -4 in Python?

Floor division always rounds down toward negative infinity. -7 / 2 is -3.5, and rounding -3.5 down gives -4, not -3.

How do you write a power or exponent in Python?

Use two asterisks: 2 ** 3 is 8. The caret symbol ^ is not a power operator in Python; it performs a bitwise XOR.