repr/str diff between Python 2 and 3

Serhiy Storchaka storchaka at gmail.com
Wed Oct 12 02:26:43 EDT 2016


On 12.10.16 04:30, Skip Montanaro wrote:
>>   https://docs.python.org/3/whatsnew/3.1.html
>>
>> It's the third hit when searching for 'float'.  Assuming I understand
> what it's saying. ;)
>
> Thanks. Is that the "David Gay's algorithm"? That seems to apply only to
> repr(), while the change I observed was in str().

In Python 2 str() for floats was equivalent to '%.12g' % x, and repr() 
-- to '%.17g' % x. In Python 3.0 str() becomes the same as repr() (this 
added too much noise). In Python 3.1 repr() (and therefore str()) was 
changed to produce more compact representation if possible. This change 
was backported to 2.7, but str() left different.





More information about the Python-list mailing list