[issue33013] Underscore in str.format with x option
Cheryl Sabella
report at bugs.python.org
Tue Mar 6 10:08:53 EST 2018
New submission from Cheryl Sabella <chekat2 at gmail.com>:
>From the doc (https://docs.python.org/3/library/string.html#format-specification-mini-language):
> The '_' option signals the use of an underscore for a thousands separator for floating point presentation types and for integer presentation type 'd'. For integer presentation types 'b', 'o', 'x', and 'X', underscores will be inserted every 4 digits. For other presentation types, specifying this option is an error.
>>> '{0:_}'.format(123456789)
'123_456_789'
>>> '{0:x}'.format(123456789)
'75bcd15'
>>> '{0:x_}'.format(123456789)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid format specifier
What am I doing wrong? I read the doc as saying that using `type` of `x` would result in the `_` separator to be inserted every 4 characters, so I was expecting the output to be '75b_cd15'.
Thanks!
----------
messages: 313330
nosy: csabella
priority: normal
severity: normal
status: open
title: Underscore in str.format with x option
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33013>
_______________________________________
More information about the Python-bugs-list
mailing list