diff options
author | Raymond Hettinger <python@rcn.com> | 2003-08-08 23:32:46 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-08-08 23:32:46 (GMT) |
commit | 0eec08794cae1aad449a95ff3aa9c8bbbc3fad9b (patch) | |
tree | 1f6045b6d1d68ab1231abffc1f7fa07b21608d09 /Doc | |
parent | a6a277d8316973ca3f546e5111430a8c4ee07181 (diff) | |
download | cpython-0eec08794cae1aad449a95ff3aa9c8bbbc3fad9b.zip cpython-0eec08794cae1aad449a95ff3aa9c8bbbc3fad9b.tar.gz cpython-0eec08794cae1aad449a95ff3aa9c8bbbc3fad9b.tar.bz2 |
Explain argument unpacking
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/tut/tut.tex | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 659ffb7..0a26d6b 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -1577,6 +1577,24 @@ def fprintf(file, format, *args): \end{verbatim} +\subsection{Unpacking Argument Lists \label{unpacking-arguments}} + +The reverse situation occurs when the arguments are already in a list +or tuple but need to be unpacked for a function call requiring separate +positional arguments. For instance, the built-in \function{range()} +function expects separate \var{start} and \var{stop} arguments. If they +are not available separately, write the function call with the +\code{*}-operator to unpack the arguments out of a list or tuple: + +\begin{verbatim} +>>> range(3, 6) # normal call with separate arguments +[3, 4, 5] +>>> args = [3, 6] +>>> range(*args) # call with arguments unpacked from a list +[3, 4, 5] +\end{verbatim} + + \subsection{Lambda Forms \label{lambda}} By popular demand, a few features commonly found in functional |