This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Improve f-strings documentation wrt format specifiers
Type: Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mariatta, docs@python, eric.smith, martin.panter
Priority: normal Keywords: patch

Created on 2017-09-15 17:34 by Mariatta, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3604 merged Mariatta, 2017-09-15 17:35
PR 3619 merged python-dev, 2017-09-16 19:00
PR 3627 merged Mariatta, 2017-09-17 14:38
PR 3628 merged python-dev, 2017-09-17 14:43
Messages (5)
msg302279 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-09-15 17:34
Provide a couple more examples of using format specifiers in f-string.
msg302350 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-09-16 19:01
New changeset 46c1052404c1a6e4d35af8e96613db8a4be75b52 by Mariatta (Miss Islington (bot)) in branch '3.6':
bpo-31487: Improve f-strings documentation (GH-3604) (GH-3619)
msg302367 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-09-17 14:43
New changeset 63c591c0b0b57870a606e8edc59afe6264e7504d by Mariatta in branch 'master':
bpo-31487: Update F-strings doc example (GH-3627)
msg302368 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-09-17 14:57
New changeset 4f6bae9677c0e5398e64c503fd3c19cae94567da by Mariatta (Miss Islington (bot)) in branch '3.6':
bpo-31487: Update F-strings doc example (GH-3627) (GH-3628)
msg302397 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-09-18 00:14
>>> 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}"
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75668
2017-09-18 00:14:24martin.pantersetnosy: + martin.panter
messages: + msg302397
2017-09-17 14:57:10Mariattasetmessages: + msg302368
2017-09-17 14:43:47python-devsetpull_requests: + pull_request3617
2017-09-17 14:43:33Mariattasetmessages: + msg302367
2017-09-17 14:38:38Mariattasetpull_requests: + pull_request3616
2017-09-16 19:01:58Mariattasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-09-16 19:01:33Mariattasetmessages: + msg302350
2017-09-16 19:00:05python-devsetpull_requests: + pull_request3610
2017-09-15 17:49:38Mariattasetversions: + Python 3.6, Python 3.7
2017-09-15 17:35:08Mariattasetkeywords: + patch
stage: patch review
pull_requests: + pull_request3595
2017-09-15 17:34:45Mariattacreate