summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2017-09-16 18:46:43 (GMT)
committerGitHub <noreply@github.com>2017-09-16 18:46:43 (GMT)
commitf3618970690b08ed88e430ba8017859b4fafc3f9 (patch)
tree2374ab11096010c567f3a06660e2dc6d62260a0a /Doc
parent0ec8c4bd10dcfd8e580628868efdd3df91038898 (diff)
downloadcpython-f3618970690b08ed88e430ba8017859b4fafc3f9.zip
cpython-f3618970690b08ed88e430ba8017859b4fafc3f9.tar.gz
cpython-f3618970690b08ed88e430ba8017859b4fafc3f9.tar.bz2
Improve f-strings documentation (GH-3604)
Provide additional examples of using format specifiers in f-strings Added examples for using integer and date format specifiers.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/reference/lexical_analysis.rst6
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst
index 1a7c6f9..baf1f09 100644
--- a/Doc/reference/lexical_analysis.rst
+++ b/Doc/reference/lexical_analysis.rst
@@ -676,6 +676,12 @@ Some examples of formatted string literals::
>>> value = decimal.Decimal("12.34567")
>>> f"result: {value:{width}.{precision}}" # nested fields
'result: 12.35'
+ >>> today = datetime(year=2017, month=1, day=27)
+ >>> f"{today:%b %d, %Y}" # using date format specifier
+ 'January 27, 2017'
+ >>> number = 1024
+ >>> f"{number:#0x}" # using integer presentation type as format specifier
+ '0x400'
A consequence of sharing the same syntax as regular string literals is
that characters in the replacement fields must not conflict with the