[Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

Richard D. Moores rdmoores at gmail.com
Mon Aug 5 14:51:18 CEST 2013


>>> import fractions
>>> fractions.Fraction(6, 21)
Fraction(2, 7)

How do I turn that Fraction(2, 7) into "1/7"? (and not 0.2857142857142857...)

Or do I have to employ fractions.gcd?

I can't seem to find the answer in the doc at
<http://docs.python.org/3/library/fractions.html#module-fractions>

Thanks,

DIck Moores


More information about the Tutor mailing list