cpython list __str__ method for floats

TheFlyingDutchman zzbbaadd at aol.com
Tue Sep 11 07:20:10 EDT 2007


On Sep 11, 4:07 am, "[david]" <da... at nospam.spam> wrote:
> returns poorly formatted values:
>
>  >>>str(13.3)
> '13.3'
>  >>>str([13.3])
> '[13.300000000000001]'
>
> [david]

There is some difference in the way repr() and str() convert floats to
strings:

>>> a = 13.3
>>> print str(a)
13.3
>>> print repr(a)
13.300000000000001
>>> a
13.300000000000001
>>> a.__str__()
'13.3'
>>> a.__repr__()
'13.300000000000001'
>>>




More information about the Python-list mailing list