]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport documentation of left-to-right evaluation order.
authorRaymond Hettinger <python@rcn.com>
Mon, 16 Dec 2002 23:19:19 +0000 (23:19 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 16 Dec 2002 23:19:19 +0000 (23:19 +0000)
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

index f7f5394ba2b2cf882c3893a144e967d02db5cbe7..f28163278dc723d3eb18e99b2b21066ab87eeed1 100644 (file)
@@ -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}}