In Python, there are two types of division, one of which is /
:
>>> 10 / 3
3.3333333333333335
/
The division evaluates to a floating-point number, even if it is exactly divisible by two integers, and the result is a floating-point number:
>>> 9 / 33.0
There is also a division that is //
called a floor divide, where the division of two integers is still an integer:
>>> 10 // 3
3
You are not mistaken, the whole number of floors apart //
is always an integer, even if not endless.
To do the exact division, you /
can use it. Because //
division takes only the integer part of the result.
Python also provides a remainder operation that can be used to divide the remainder of two integers:
>>> 10 % 31
The result is always an integer, regardless of whether the integer //
divides or takes the remainder, so the result of the integer operation is always accurate.
Why is the integer division of Python accurate???