"Richard D. Moores" <[email protected]> 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__

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to