What Does // Mean in Python? Floor Division Explained
If you have read Python source and hit the `//` operator, you probably wondered whether someone fat-fingered a division. They did not. In Python, `//` is the floor division operator: it divides two numbers and rounds the result *down* to the nearest whole number. A single `/` gives you true division and returns a float; `//` floors that result.
That one-line definition is correct but it hides the part that bites people in production: how `//` behaves with negative numbers. Let me walk through every case with runnable code so you never guess again.
Key Takeaways
• `//` is floor division — it divides and rounds *down* (toward negative infinity), not toward zero.
• `/` (true division) always returns a `float`; `//` returns the floored value (`int` if both operands are `int`).
• `7 / 2` is `3.5`, but `7 // 2` is `3`.
• With negatives, `-7 // 2` is `-4`, not `-3` — this is the classic gotcha.
• `//` and `%` (modulo) satisfy the identity `(a // b) * b + (a % b) == a` for all valid inputs.
• Common uses: pagination, splitting into groups, time conversions, and array indexing.
What does // actually mean in Python?
The `//` operator performs floor division. It takes the quotient of two numbers and applies the floor function — rounding *down* to the nearest integer.
“`python print(7 // 2) # 3 print(10 // 3) # 3 print(20 // 4) # 5 print(1 // 4) # 0 “`
Contrast that with regular division using a single slash:
“`python print(7 / 2) # 3.5 print(10 / 3) # 3.3333333333333335 print(20 / 4) # 5.0 “`
So `7 / 2` keeps the fractional part as a float, while `7 // 2` throws away the fraction and floors the result to `3`. If you only ever work with non-negative numbers, you can read `//` as “divide and drop the decimal” — and you will be right every time. The trouble starts at zero and below, which we will get to shortly.
How is // different from / in Python?
These two operators answer different questions. `/` asks “what is the exact ratio?” and `//` asks “how many whole times does the divisor fit?”
| Operator | Name | What it does | Example | Result |
|---|---|---|---|---|
| `/` | True division | Exact quotient, always a float | `7 / 2` | `3.5` |
| `//` | Floor division | Quotient rounded *down* | `7 // 2` | `3` |
| `%` | Modulo | Remainder after floor division | `7 % 2` | `1` |
| `**` | Exponent | Power | `7 ** 2` | `49` |
| `divmod()` | Both | `(a // b, a % b)` as a tuple | `divmod(7, 2)` | `(3, 1)` |
The return *type* matters too. True division always hands back a `float`, even when the math is clean:
“`python result = 20 / 4 print(result) # 5.0 print(type(result)) #
result = 20 // 4 print(result) # 5 print(type(result)) #
If both operands are integers, `//` returns an `int`. The moment a `float` enters the expression, the result becomes a `float` — floored, but still a float (more on that below).
For a wider tour of arithmetic, comparison, and bitwise operators, see the .
How does // behave with negative numbers?
This is where intuition fails. Most people expect floor division to “chop off the decimal,” which would mean rounding *toward zero*. Python does not do that. It rounds *toward negative infinity*.
“`python print(7 // 2) # 3 (chop and floor agree) print(-7 // 2) # -4 (NOT -3) print(7 // -2) # -4 (NOT -3) print(-7 // -2) # 3 “`
Look at `-7 // 2`. The true quotient is `-3.5`. “Chopping the decimal” would give `-3`. But flooring `-3.5` — moving *down* the number line — gives `-4`. Python chose floor, so the answer is `-4`.
The `//` operator surprises people most with negative numbers, because Python floors toward *negative infinity*, not toward zero. So `-7 // 2` is `-4`, not the `-3` you would get from “chop off the decimal.” This is not a bug; it is a deliberate, mathematically consistent choice that keeps the identity `(a // b) * b + (a % b) == a` always true, which in turn makes Python’s modulo well-behaved (the remainder always carries the sign of the *divisor*). The practical lesson: `//` means “round DOWN” (toward minus infinity), not “truncate toward zero.” They are identical for positives but diverge for negatives, and mixing them up is a classic off-by-one bug in anything doing math with possibly-negative values.
If you genuinely want truncation toward zero (the C-style behavior), use `math.trunc` or `int()` on a true-division result:
“`python import math
print(-7 // 2) # -4 (floor) print(int(-7 / 2)) # -3 (truncate toward zero) print(math.trunc(-7 / 2)) # -3 (truncate toward zero) “`
Know which one your problem needs before you write it down.
What does // do with floats?
Floor division works on floats too. It still floors the result, but because a `float` is involved, the return type is `float`:
“`python print(7.0 // 2) # 3.0 print(7 // 2.0) # 3.0 print(7.5 // 2) # 3.0 print(-7.5 // 2) # -4.0 “`
Notice `7.0 // 2` returns `3.0`, not `3`. The value is floored, but the type is preserved as a float. The same negative-infinity rule applies: `-7.5 // 2` floors `-3.75` down to `-4.0`.
Floating-point representation can also produce results that look off by a hair in edge cases, which is one more reason to prefer integer operands when you need exact counts.
How do // and % work together?
Floor division and modulo are two halves of the same operation. The relationship is fixed by this identity, which holds for every valid `a` and `b`:
“` (a // b) * b + (a % b) == a “`
You can verify it directly:
“`python a, b = 17, 5 print(a // b) # 3 print(a % b) # 2 print((a // b) * b + (a % b)) # 17 -> identity holds
a, b = -17, 5 print(a // b) # -4 print(a % b) # 3 (sign follows the divisor, +5) print((a // b) * b + (a % b)) # -17 -> still holds “`
Because Python floors toward negative infinity, the remainder from `%` always takes the sign of the divisor. With `-17 % 5` you get `3`, not `-2`. That property is exactly why Python’s modulo is so reliable for things like wrapping array indices or cycling through a fixed set of buckets.
When you need both the quotient and the remainder, do not compute them separately — use `divmod()`, which returns them as a tuple in one call:
“`python quotient, remainder = divmod(17, 5) print(quotient, remainder) # 3 2
print(divmod(-17, 5)) # (-4, 3) “`
For a deeper look at the remainder operator on its own, see .
What are practical uses for // in real code?
Floor division shows up anywhere you need to convert a quantity into whole units. Here are the patterns I reach for most.
Pagination. Given a total number of items and a page size, how many pages do you need? Plain `//` undercounts the last partial page, so add one with a small ceiling trick:
“`python total_items = 47 per_page = 10
full_pages = total_items // per_page # 4 total_pages = -(-total_items // per_page) # 5 (ceiling division) print(full_pages, total_pages) # 4 5 “`
The `-(-a // b)` idiom is ceiling division: negate, floor, negate back. It is concise and avoids importing `math.ceil`.
Splitting items into groups. To bucket an index into fixed-size groups:
“`python items_per_group = 3 for index in range(9): group = index // items_per_group print(index, “->”, group)
“`
Time conversions. Turn raw seconds into minutes and seconds with one `divmod`:
“`python total_seconds = 3725 minutes, seconds = divmod(total_seconds, 60) hours, minutes = divmod(minutes, 60) print(f”{hours}h {minutes}m {seconds}s”) # 1h 2m 5s “`
Index math. Mapping a flat index into a 2D grid of fixed width:
“`python width = 4 flat_index = 10 row = flat_index // width # 2 col = flat_index % width # 2 print(row, col) # 2 2 “`
These patterns are the bread and butter of backend scripts, data pipelines, and CLI tools. If you are setting up a place to run them, the walkthrough covers execution from the terminal to scheduled jobs.
Was // always the floor division operator?
Not quite, and this trips up anyone reading older code. The behavior of `/` changed between Python 2 and Python 3.
- Python 2: `/` performed *integer* division when both operands were integers. So `7 / 2` returned `3`, silently flooring. You had to write `7 / 2.0` to get `3.5`. The `//` operator existed too, as an explicit floor-division operator.
- Python 3: `/` is *always* true division and returns a float. `7 / 2` is `3.5`. If you want flooring, you ask for it explicitly with `//`.
“`python
print(7 / 2) # 3.5 print(7 // 2) # 3
“`
The lesson: in modern Python, `//` is the *only* way to get floor division. Never rely on `/` to floor — that was a Python 2 quirk, and it is gone. This is also why porting old scripts can quietly change numeric results if you do not audit every division. The fundamentals here connect to broader if you are still building your footing.
Build Python projects on infrastructure you control. DarazHost VPS and dedicated servers give developers a real Python environment with full control — install any Python version, run scripts and apps, and build with confidence on guaranteed resources. It is the controllable home your Python projects deserve, backed by 24/7 support. When your floor-division-heavy data pipeline needs to run on a schedule without surprises, a dedicated environment beats a shared sandbox every time.
For the bigger picture on owning your stack, read the complete guide to a real developer environment you control.
Frequently asked questions
What does // mean in Python? `//` is the floor division operator. It divides the left number by the right and rounds the result *down* to the nearest whole number. For example, `7 // 2` is `3` and `10 // 3` is `3`. It differs from `/`, which returns the exact float quotient.
What is the difference between / and // in Python? `/` is true division and always returns a `float` (`7 / 2` is `3.5`). `//` is floor division and returns the result rounded down (`7 // 2` is `3`). If both operands of `//` are integers, the result is an `int`; if a float is involved, it is a floored `float`.
Why is -7 // 2 equal to -4 and not -3? Because `//` rounds toward negative infinity, not toward zero. The true quotient is `-3.5`, and flooring moves *down* the number line to `-4`. If you want to truncate toward zero instead, use `int(-7 / 2)` or `math.trunc(-7 / 2)`, which both give `-3`.
Does // always return an integer? No. It returns an `int` only when both operands are integers. If either operand is a `float`, `//` returns a floored `float` — for example, `7.0 // 2` is `3.0`, not `3`.
How are // and % related? They are paired: for any valid `a` and `b`, `(a // b) * b + (a % b) == a`. The `%` remainder always carries the sign of the divisor. Use `divmod(a, b)` to get both the floor quotient and the remainder in a single call.