There are two types of division in Python:
Floating-point division:
When we use the /
operator to divide two integer numbers (x/y
), we will get a floating-point number as the result.
Floor division:
When we use the //
operator to divide two integers (x//y
), we will get an integer number. This type of division is also known as integer division.
Note: In mathematics, a rational number can be expressed as a fraction , where is an integer in the numerator and is an integer in the denominator, and 0.
In Python, rational numbers exist and can be represented with the use of the fractions
module. To use this module, we have to first import it into our program by running the following command:
from fractions import Fraction
Fraction(22,7)
In the Fraction()
constructor, the first parameter is the numerator, and the second parameter is the denominator.
from fractions import Fractionprint(Fraction(22,7))
Free Resources