[Tutor] Fraction - differing interpretations for number and string

Danny Yoo danny.yoo at gmail.com
Thu Apr 16 10:55:06 CEST 2015


On Apr 16, 2015 1:52 AM, "Danny Yoo" <danny.yoo at gmail.com> wrote:
>
>
> On Apr 16, 2015 1:32 AM, "Jim Mooney" <cybervigilante at gmail.com> wrote:
> >
> > Why does Fraction interpret a number and string so differently? They
come
> > out the same, but it seems rather odd
> >
> > >>> from fractions import Fraction
> > >>> Fraction(1.64)
> > Fraction(7385903388887613, 4503599627370496)
> > >>> Fraction("1.64")
> > Fraction(41, 25)
> > >>> 41/25
> > 1.64
> > >>> 7385903388887613 / 4503599627370496
> > 1.64
>
> In many systems, if everything is the same shape, then certain operations
might be implemented more quickly by making uniform assumptions.  If all my
clothes were the same, for example, maybe I'd be able to sorry my laundry
more quickly.  And if all my Tupperware were the same size, then maybe my
cabinets wouldn't be the nest of ill fitting plastic that it is now.

Substitute "sorry" with "sort".  Sorry!  :p


More information about the Tutor mailing list