From cc80e80c8af1114db77cffc1e82c1631b6e01e5b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 16 Dec 2002 23:19:19 +0000 Subject: [PATCH] Backport documentation of left-to-right evaluation order. Highlight the difference for dictionaries and provide Py2.2.3 users which advanced notice that the evaluation order will change for Py2.3. --- Doc/ref/ref5.tex | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Doc/ref/ref5.tex b/Doc/ref/ref5.tex index f7f5394ba2b2..f28163278dc7 100644 --- a/Doc/ref/ref5.tex +++ b/Doc/ref/ref5.tex @@ -1021,6 +1021,37 @@ tuple, but rather yields the value of that expression. \code{()}.) \indexii{trailing}{comma} +\section{Evaluation order\label{evalorder}} +\indexii{evaluation}{order} + +Python evaluates expressions from left to right. Notice that while +evaluating an assignment, the right-hand side is evaluated before +the left-hand side. + +In the following lines, expressions will be evaluated in the +arithmetic order of their suffixes: + +\begin{verbatim} +expr1, expr2, expr3, expr4 +(expr1, expr2, expr3, expr4) +expr1 + expr2 * (expr3 - expr4) +func(expr1, expr2, *expr3, **expr4) +expr3, expr4 = expr1, expr2 +\end{verbatim} + +Dictionaries are currently an exception to the rule and they evaluate +in the following order: + +\begin{verbatim} +{expr2: expr1, expr4: expr3} +\end{verbatim} + +In Python 2.3, the order will be changed to be consistent with +other expressions: + +\begin{verbatim} +{expr1: expr2, expr3: expr4} +\end{verbatim} \section{Summary\label{summary}} -- 2.47.3