Mailing List Archive

python/dist/src/Doc/tut tut.tex,1.156.4.1.2.9,1.156.4.1.2.10
Update of /cvsroot/python/python/dist/src/Doc/tut
In directory usw-pr-cvs1:/tmp/cvs-serv22047

Modified Files:
Tag: release22-maint
tut.tex
Log Message:
Added a tutorial note and example regarding the scope of loop variables
in a list comprehension. Includes a justification and a comparision
to regular for-loops.

Closes SF bug 605047.



Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.156.4.1.2.9
retrieving revision 1.156.4.1.2.10
diff -C2 -d -r1.156.4.1.2.9 -r1.156.4.1.2.10
*** tut.tex 14 Aug 2002 15:27:19 -0000 1.156.4.1.2.9
--- tut.tex 6 Sep 2002 18:09:22 -0000 1.156.4.1.2.10
***************
*** 1863,1866 ****
--- 1863,1879 ----
\end{verbatim}

+ To make list comprehensions match the behavior of \keyword{for}
+ loops, assignments to the loop variable remain visible outside
+ of the comprehension:
+
+ \begin{verbatim}
+ >>> x = 100 # this gets overwritten
+ >>> [x**3 for x in range(5)]
+ [0, 1, 8, 27, 64]
+ >>> x
+ 4 # the final value for range(5)
+ >>
+ \end{verbatim}
+

\section{The \keyword{del} statement \label{del}}