diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-16 19:01:32 (GMT) |
---|---|---|
committer | Mariatta <Mariatta@users.noreply.github.com> | 2017-09-16 19:01:32 (GMT) |
commit | 46c1052404c1a6e4d35af8e96613db8a4be75b52 (patch) | |
tree | cbf3255ea7a0cba4ea0374e38fc811d2a2ffedee /Doc | |
parent | d3cba8175ca48d33a4e0117109a44935a1cec658 (diff) | |
download | cpython-46c1052404c1a6e4d35af8e96613db8a4be75b52.zip cpython-46c1052404c1a6e4d35af8e96613db8a4be75b52.tar.gz cpython-46c1052404c1a6e4d35af8e96613db8a4be75b52.tar.bz2 |
bpo-31487: Improve f-strings documentation (GH-3604) (GH-3619)
Provide additional examples of using format specifiers in f-strings
Added examples for using integer and date format specifiers.
(cherry picked from commit f3618970690b08ed88e430ba8017859b4fafc3f9)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/reference/lexical_analysis.rst | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index fff31a3..3305f46 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 |