In Python, floor division is a division operation that rounds the result down to the nearest integer (toward negative infinity). It is denoted by the double forward slash //
operator.
The floor division operation is used to obtain the quotient of a division without any decimal places. It discards the fractional part of the division result, leaving only the whole number part.
Here’s how floor division works in Python:
result = dividend // divisor
dividend
is the number you want to divide.divisor
is the number you want to divide by.
The result will be the whole number obtained after dividing dividend
by divisor
, rounded down to the nearest integer.
Python floor division example
Here’s a practical example:
# Floor division example
dividend = 10
divisor = 3
result = dividend // divisor
print(result)
Output:
In this example, dividend
is 10, divisor
is 3, and result
will store the floor division result, which is 3. The fractional part of the division result is discarded, and the output is always an integer value (either positive or negative, depending on the signs of the numbers involved).
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.