Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

In Python, / performs true division, while // divides and rounds the quotient down to the nearest whole value. For example, 17 / 3 is 5.666666666666667, but 17 // 3 is 5.

What is the difference between / and //?

The operators both divide, but they handle the quotient differently. True division with / preserves a fractional result. Floor division with // applies the mathematical floor function: it returns the greatest integer less than or equal to the quotient for integer operands.

Operator Operation Example with integers Practical use
/ True division; preserves the fractional quotient. 17 / 3 → 5.666666666666667 (a float) Ratios, averages, or measurements where a fractional result matters.
// Floor division; applies floor to the quotient. 17 // 3 → 5 (an integer) Whole-unit counts or calculations that use a quotient and remainder.

The examples and integer-operand behavior are documented in the Python 3.10 tutorial and the language reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why does -22 // 10 return -3?

Floor division is not the same as dropping the fractional part or rounding toward zero. The quotient of -22 / 10 is -2.2; its floor is -3, the next integer in the negative direction. Thus -22 // 10 returns -3. Similarly, 22 // -10 is -3, because 22 / -10 is also -2.2.

This is intentional: Python’s floor-division and modulo rules work together so the remainder has the sign of the divisor, unless it is zero. The Python FAQ explains the negative case and its connection to modulo.

How do result types work?

For ordinary built-in integer operands, / returns a float, while // returns an integer. The broader rule depends on the operand types: Python converts numeric operands to a common type where applicable, so do not assume those integer examples describe every numeric combination. The language reference states that integer division yields a float and integer floor division yields an integer.

User-defined numeric types can customize these operators with their corresponding special methods, so their behavior may differ from built-in numbers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How do //, %, and divmod() fit together?

Floor division is often useful when you need both the number of whole groups and what remains. Python defines the relationship x == (x // y) * y + (x % y); equivalently, divmod(x, y) returns (x // y, x % y).

17 // 3       # 5
17 % 3        # 2
divmod(17, 3) # (5, 2)

For negative values, the same relationship holds, and the remainder follows the sign of the divisor (the second operand), or is zero. This is why floor division may give a different-looking result from truncating toward zero.

What errors and limitations should you know?

  • Dividing by zero with either operator raises ZeroDivisionError.
  • Floor division is not defined for complex numbers.

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.