The fraction class is found in Lib/fractions.py so to import:

from fractions import Fraction

There are a number of ways to instantiate the Fraction class. First, you can pass in the numerator and the denominator.

>>> Fraction(1, 2) Fraction(1, 2)

Or instantiate with another fraction:

>>> f = Fraction(1, 2) >>> Fraction(f) Fraction(1, 2)

Instantiate with a float:

>>> Fraction(2.5) Fraction(5, 2)

Or with a decimal:

>>> from decimal import Decimal >>> Fraction(Decimal('1.1')) Fraction(11, 10)

Lastly, and probably the most interesting - you can instantiate with a string:

>>> Fraction('9/16') Fraction(9, 16)

Ultimately, the Fraction class is designed so that there is very little processing you have to do before instantiating the class. It knows how to deal with multiple data types.