This class implements rational numbers.
In the two-argument form of the constructor, Fraction(8, 6) will
produce a rational number equivalent to 4/3. Both arguments must
be Rational. The numerator defaults to 0 and the denominator
defaults to 1 so that Fraction(3) == 3 and Fraction() == 0.
Fractions can also be constructed from:
- numeric strings similar to those accepted by the
float constructor (for example, '-2.3' or '1e10')
- strings of the form '123/456'
- float and Decimal instances
- other Rational instances (including integers)
3.2: The Fraction constructor now accepts float and decimal.Decimal instances.
3.9: The math.gcd() function is now used to normalize the numerator and denominator. math.gcd() always returns an int type. Previously, the GCD type depended on numerator and denominator.
3.11: Underscores are now permitted when creating a Fraction instance from a string, following PEP 515 rules.
3.11: Fraction implements __int__ now to satisfy typing.SupportsInt instance checks.
3.12: Space is allowed around the slash for string inputs: Fraction('2 / 3').
3.12: Fraction instances now support float-style formatting, with presentation types "e", "E", "f", "F", "g", "G" and "%"".
3.13: Formatting of Fraction instances without a presentation type now supports fill, alignment, sign handling, minimum width and grouping.
3.14: The Fraction constructor now accepts any objects with the as_integer_ratio() method.