In a Python (3.6.7) interactive shell on Ubuntu 18, both
>>> n = str(3.140000000000000124344978758017532527446746826171875)
>>> print(n)
and
>>> print(3.140000000000000124344978758017532527446746826171875)
yield 3.14
. While
>>> print('3.140000000000000124344978758017532527446746826171875')
yields 3.140000000000000124344978758017532527446746826171875
Why is this?
Note; I am not asking why floating-point numbers lose precision, but specifically, why the use of str(n)
and 'n'
(quotes) behave differently with print()
.