[Tutor] a print puzzle

Richard D. Moores rdmoores at gmail.com
Thu Dec 2 20:09:34 CET 2010


On Thu, Dec 2, 2010 at 03:13, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Richard D. Moores" <rdmoores at gmail.com> wrote
>
>>>>> s = [.1,.1,.1,.1,.1,.1,.1,.1,.1,.1]
>>>>> sum(s)
>>
>> 0.9999999999999999
>
> This uses repr() to display the result
>
>>>>> print(sum(s))
>>
>> 1.0      Why?
>
> This uses str() to display the result.
>
> In many cases str() calls repr() but in other cases str() is a more user
> friendly format. repr() tends to be a developers eye view of things.
> This is one reason that in my tutorial I always use print() to display
> results. The output is more newbie friendly that way :-)
>
> I suspect the details will be revealed by a search for documentation
> on __repr__

I found nothing that helped as much as you have already.

Thanks,

Dick


More information about the Tutor mailing list