Added section on order of evaluation.

This commit is contained in:
Eric V. Smith 2015-08-28 11:16:23 -04:00
parent 174ea8308e
commit 75f463a375
1 changed files with 17 additions and 3 deletions

View File

@ -602,10 +602,24 @@ having 2 expressions::
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
-------------------------------