In Python, / performs true division, while // divides and applies the mathematical floor: for example, 17 / 3 is 5.666666666666667, but 17 // 3 is 5. With negative numbers, floor moves toward negative infinity, so -22 // 10 is -3, not -2.
How the two operators differ
| Operator | Operation | Example with integers | Practical use |
|---|---|---|---|
/ |
True division: returns the quotient without flooring it. | 17 / 3 gives 5.666666666666667. |
Use it when a fractional result matters, such as calculating a ratio or measurement. |
// |
Floor division: applies mathematical floor to the quotient. | 17 // 3 gives 5. |
Use it when you need a whole-number quotient or are working with quotient-and-remainder arithmetic. |
For integer operands, / produces a float and // produces an integer. These are the usual results for built-in integers, not a universal rule for every numeric type: mixed operands are converted to a common type, which affects the result type. User-defined numeric classes can also customize these operations.
As an Amazon Associate I earn from qualifying purchases.
Why negative floor division can surprise you
Floor does not mean removing the digits after the decimal point or rounding toward zero. It means rounding down to the next integer, or keeping the integer unchanged when the quotient is already whole. In mathematical terms, floor moves toward negative infinity.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →-22 / 10 # -2.2
-22 // 10 # -3
22 // -10 # -3
Since -2 is greater than -2.2, it is not the floor of that quotient; -3 is. This is why applying the “drop the decimal part” shortcut to negative values gives the wrong answer.
#1 Best Overall
How // relates to % and divmod()
Floor division is paired with the modulo operator, %. For the supported numeric values, Python documents the relationship x == (x // y) * y + (x % y). The remainder is zero or has the sign of the divisor, y.
17 // 3 # 5
17 % 3 # 2
divmod(17, 3) # (5, 2)
divmod(x, y) returns the floor-division result and the remainder together: (x // y, x % y). This relationship also accounts for the negative result: with -22 // 10 == -3, the remainder is 8, and (-3 * 10) + 8 equals -22. The Python FAQ explains that this behavior is tied to keeping the remainder’s sign consistent with the divisor.
Rank #2
Errors and type limits
- Dividing by zero with either operator raises
ZeroDivisionError. - Floor division is not defined for complex numbers.
- For custom numeric classes, the operators can be implemented or customized by the class, so built-in-number behavior may not apply.
For the ordinary built-in integer examples above, choose / when you need the fractional quotient and // when you need the floored quotient. The Python Language Reference documents the operator semantics in Binary arithmetic operations; the official Numbers tutorial provides basic examples, and the Python FAQ explains the negative case.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




