[Python-checkins] peps: Added section on order of evaluation.

eric.smith python-checkins at python.org
Fri Aug 28 17:16:18 CEST 2015


https://hg.python.org/peps/rev/548cbfbd3d8f
changeset:   6000:548cbfbd3d8f
user:        Eric V. Smith <eric at trueblade.com>
date:        Fri Aug 28 11:16:23 2015 -0400
summary:
  Added section on order of evaluation.

files:
  pep-0498.txt |  20 +++++++++++++++++---
  1 files changed, 17 insertions(+), 3 deletions(-)


diff --git a/pep-0498.txt b/pep-0498.txt
--- a/pep-0498.txt
+++ b/pep-0498.txt
@@ -602,10 +602,24 @@
 
   f'{x:.{width}}'
 
-Expressions with side effects
------------------------------
+Evaluation order of expressions
+-------------------------------
 
-xxx
+The expressions in an f-string are evaluated in left-to-right
+order. This is detectable only if the expressions have side effects::
+
+  >>> def fn(l, incr):
+  ...    result = l[0]
+  ...    l[0] += incr
+  ...    return result
+  ...
+  >>> lst = [0]
+  >>> f'{fn(lst,2)} {fn(lst,3)}'
+  '0 2'
+  >>> f'{fn(lst,2)} {fn(lst,3)}'
+  '5 7'
+  >>> lst
+  [10]
 
 Expressions used multiple times
 -------------------------------

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list