>> "{}".format(1241.123124) '1241.123124' >>> "{:g}".format...">

Why "{}". format (1241.123124) is different from the format "{: g}". (1241.123124)

>>> "{}".format(1241.123124)
'1241.123124'
>>> "{:g}".format(1241.123124)
'1241.12'

The documentation here: https://docs.python.org/2/library/string.html

It says

No Same as g.

+4
source share
1 answer

This is a documentation error. There is an open bug report in the Python bug tracker . Let me hope that he will be considered:

The documentation for the None format (empty) for floats indicates that this is equivalent to the g format. This does not seem to be correct ( Exact definition of floating-line formatting? ).

Python 3.4 (https://docs.python.org/3.4/library/string.html#format-specification-mini-language) , , Python 2.7.

None Python 2.7 (, Python 3.4, ).

+5

All Articles