[docs] [issue31487] Improve f-strings documentation wrt format specifiers

Martin Panter report at bugs.python.org
Sun Sep 17 20:14:24 EDT 2017

Martin Panter added the comment:

>>> f"{number:#0x}"  # using integer format specifier

It’s not clear what your purpose was adding the above line, but the zero flag (0) does nothing because there is no “width” field. I think it could be misleading, because it is actually the “#x” codes that generate the “0x” prefix.

If you want to illustrate a minimum width, I suggest something like

>>> f"{number:#06x}"

or (if the number is never negative)

>>> f"0x{number:04X}"

Or if you don’t care about the width:

>>> f"{number:#x}"

nosy: +martin.panter

Python tracker <report at bugs.python.org>

More information about the docs mailing list