[Python-checkins] peps: Small typos. Added section about nested expressions inside format specifiers.
eric.smith
python-checkins at python.org
Mon Aug 10 15:17:37 CEST 2015
https://hg.python.org/peps/rev/32f2e29a125c
changeset: 5950:32f2e29a125c
user: Eric V. Smith <eric at trueblade.com>
date: Mon Aug 10 09:17:36 2015 -0400
summary:
Small typos. Added section about nested expressions inside format specifiers.
files:
pep-0498.txt | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/pep-0498.txt b/pep-0498.txt
--- a/pep-0498.txt
+++ b/pep-0498.txt
@@ -229,7 +229,17 @@
Format specifiers
-----------------
-Format specifiers are not interpreted by the f-string parser. Just as
+Format specifiers may also contain evaluated expressions. This allows
+code such as::
+
+ >>> width = 10
+ >>> precision = 4
+ >>> value = decimal.Decimal('12.34567')
+ >>> f'result: {value:{width}.{prevision}}'
+ 'result: 12.35'
+
+Once expressions in a format specifier are evaluated (if necessary),
+format specifiers are not interpreted by the f-string evaluator. Just as
in str.format(), they are merely passed in to the __format__() method
of the object being formatted.
@@ -325,7 +335,7 @@
Most of the discussions on python-ideas [#]_ focused on a few issues:
- Whether to allow full Python expressions.
- - How to designate f-strings, and how specify the locaton of
+ - How to designate f-strings, and how to specify the location of
expressions in them.
- How to concatenate adjacent strings and f-strings.
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list