floating point glitch
Peter Hansen
peter at engcorp.com
Tue Sep 28 10:06:13 EDT 2004
Michael Hoffman wrote:
> Tim Roberts wrote:
>
>> Right! That's the point. str() is the perfect solution in those cases
>> where you want the language to lie to you. In many cases, that IS
>> what you
>> want. repr() is the perfect solution when you need an invertible
>> function.
>
> repr() does not provide an invertible function if you are using it on a
> list, as was pointed out here, since list.__repr__() essentially calls
> str() for its float members rather than repr().
It does?
>>> [0.66]
[0.66000000000000003]
>>> repr([0.66])
[0.66000000000000003]'
>>> str([0.66])
[0.66000000000000003]'
>>> str(0.66)
'0.66'
>>> repr(0.66)
'0.66000000000000003'
-Peter
More information about the Python-list
mailing list