What you are seeing is the difference between the formatting choices made by str(float)
and repr(float)
. In Python 2.x, str(float)
returns 12 digits while repr(float)
returns 17 digits. In its interactive mode, Python uses str()
to format the result. That accounts for the 12 digits of precision when formatting a float. But when the result is a tuple or list, the string formatting logic uses repr()
to format each element.
The output of repr(float)
must be able to be converted back to the original value. Using 17 digits of precision guarantees that behavior. Python 3 uses a more sophisticated algorithm that returns the shortest string that will round-trip back to the original value. Since repr(float)
frequently returns a more friendly appearing result, str(float)
was changed to be the same as repr(float)
.