This is a module which supports for rational number arithmetic. It creates a Fraction instance from numbers, floats, integers, strings, and decimals. Fraction has great significance in python and in the field of data science.
Fraction Instances –
A pair of integers construct it, another rational number or a string. These instances are hashable in nature, and they are immutable.
- Class fractionsFraction(numerator=0, denominator=1): In this, it’s the necessesity that the numerator and the denominator are instances of numbers. So, fraction instance and a rational with value = (numerator/denominator) is return. In case the denominator is zero, a zerodivision error is there.
- class fractionsFraction(other_fraction): It’s the necessasity the other_function is instance of numbers. So, rational and fraction instance with equal values is in return.
- class fractions.Fraction(float) – It is required that the float instance and a fraction instance with same value is returned.
- class fractionsFraction(decimal): In this, it’s the necessasity the decimal instance and a fraction instance with same value is in return.
- class fractionsFraction(string) – It is required the string or Unicode instance and a fraction instance with similar value is returned.
- limit_denominator(max_denominator=1000000):
- It is useful for finding rational approximations to a given floating-point number.
- This is a module that finds and returns the fraction closest to self, which has denominator at most max_denominator.
- It’s also there for returning the numerator of given fraction in lowest term using the numerator property and denominator using denominator
Mathematical Operations on Fractions:
Fraction based Calculations by Functions of Math Module:
So, to see more about modules in python for data science, you can check this and this as well.
