New submission from Cheryl Sabella <>:

>From the doc 

> 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)
>>> '{0:x}'.format(123456789)
>>> '{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'.


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 <>
Python-bugs-list mailing list

Reply via email to