diff options
author | Raymond Hettinger <python@rcn.com> | 2003-08-30 23:21:32 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-08-30 23:21:32 (GMT) |
commit | 57d71289a1243aa6ee7d3d3532659d97d6ef2520 (patch) | |
tree | b3d169445ba812c806da629d7247a4d875160b4d /Doc/tut | |
parent | f9f4c6945e14f5ad7f29085fcd756645348b13ae (diff) | |
download | cpython-57d71289a1243aa6ee7d3d3532659d97d6ef2520.zip cpython-57d71289a1243aa6ee7d3d3532659d97d6ef2520.tar.gz cpython-57d71289a1243aa6ee7d3d3532659d97d6ef2520.tar.bz2 |
SF patch #797868: Tutorial, sec. 5.1.4 could contain an extra example
(Revised from the original patch contributed by Michal Pasternak.)
Also, make a couple minor fixups elsewhere.
Diffstat (limited to 'Doc/tut')
-rw-r--r-- | Doc/tut/tut.tex | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 9b8d0ba..a730860 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -122,7 +122,7 @@ written in Python are typically much shorter than equivalent C or the high-level data types allow you to express complex operations in a single statement; \item -statement grouping is done by indentation instead of begin/end +statement grouping is done by indentation instead of beginning and ending brackets; \item no variable or argument declarations are necessary. @@ -517,7 +517,7 @@ magnitude (as a float) or \code{z.real} to get its real part. >>> float(a) Traceback (most recent call last): File "<stdin>", line 1, in ? -TypeError: can't convert complex to float; use e.g. abs(z) +TypeError: can't convert complex to float; use abs(z) >>> a.real 3.0 >>> a.imag @@ -1925,6 +1925,14 @@ SyntaxError: invalid syntax [8, 12, -54] \end{verbatim} +List comprehensions are much more flexible than \function{map()} and can be +applied to functions with more than one argument and to nested functions: + +\begin{verbatim} +>>> [str(round(355/113.0, i)) for i in range(1,6)] +['3.1', '3.14', '3.142', '3.1416', '3.14159'] +\end{verbatim} + To make list comprehensions match the behavior of \keyword{for} loops, assignments to the loop variable remain visible outside of the comprehension: |