Level 1
0 / 100 XP

Division: the two ways

Division in Python has a trap that catches almost every beginner — and plenty of experienced developers too.

There are two division operators and they behave very differently.

Regular division /

The / operator always returns a float — even when the result is a whole number:

Python
print(10 / 2) # 5.0 print(9 / 3) # 3.0 print(7 / 2) # 3.5

Notice that 10 / 2 gives 5.0, not 5. Python promotes the result to a float every single time.

Floor division //

The // operator divides and then rounds down to the nearest whole number:

Python
print(10 // 2) # 5 print(9 // 3) # 3 print(7 // 2) # 3

7 // 2 gives 3 — not 3.5, not 4. It always rounds down, never up.

The difference matters

Python
total_seconds = 150 minutes = total_seconds // 60 seconds = total_seconds % 60 print(minutes) # 2 print(seconds) # 30

If you used / here you'd get 2.5 minutes — which isn't what you want. // and % work together naturally whenever you're splitting things into groups.

Negative numbers round down too

"Round down" means toward negative infinity — not toward zero:

Python
print(-7 // 2) # -4, not -3

This surprises people. -7 / 2 is -3.5, and rounding down from -3.5 gives -4. Worth knowing before it bites you.

Key takeaways

  • / always returns a float — even 10 / 2 gives 5.0
  • // returns a whole number, always rounding down
  • // and % are a natural pair — use them together when splitting into groups
  • Floor division rounds toward negative infinity, not toward zero