// Floor division
Last updated: 2026-09-22
// Floor division
// returns the floor of division.
| Category | Operators |
|---|---|
| Kind | Operator |
| Python Version | all |
📝 Syntax
a // b
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
3
-4
3.0
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhy is -7 // 2 equal to -4 and not -3?
ABecause `//` floors toward negative infinity: `-7/2 = -3.5`, and flooring gives `-4`. `int(-7/2)` truncates toward zero and gives `-3`; the two differ for negative numbers.
QWhat is the relationship between // and %?
AThe identity `a == (a // b) * b + (a % b)` always holds; the two always work together. The sign of the remainder follows the divisor, so when `-7 // 2` is `-4`, `-7 % 2` is `1`.
QWhat type does // return for floats?
AIt returns a float, e.g. `7.5 // 2` gives `3.0`. Only when both operands are ints does it return an int.