Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

Python `/` vs `//`: True Division and Floor Division

Python `/` returns the true quotient, while `//` applies mathematical floor. See integer and negative-number examples, plus how floor division relates to modulo.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
-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.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.