[Python-checkins] Improve f-strings documentation (GH-3604)

Mariatta webhook-mailer at python.org
Sat Sep 16 14:46:45 EDT 2017


https://github.com/python/cpython/commit/f3618970690b08ed88e430ba8017859b4fafc3f9
commit: f3618970690b08ed88e430ba8017859b4fafc3f9
branch: master
author: Mariatta <Mariatta at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2017年09月16日T11:46:43-07:00
summary:
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.
files:
M Doc/reference/lexical_analysis.rst
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst
index 1a7c6f9c753..baf1f09dff2 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


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /