Added example for the ** operator in function calls

This commit is contained in:
Georg Brandl 2005-11-22 19:50:14 +00:00
parent 4bd165afa3
commit 3c9f9ac62b
1 changed files with 14 additions and 0 deletions

View File

@ -1642,6 +1642,20 @@ are not available separately, write the function call with the
[3, 4, 5]
\end{verbatim}
In the same fashion, dictionaries can deliver keyword arguments with the
\code{**}-operator:
\begin{verbatim}
>>> def parrot(voltage, state='a stiff', action='voom'):
... print "-- This parrot wouldn't", action,
... print "if you put", voltage, "volts through it.",
... print "E's", state, "!"
...
>>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
>>> parrot(**d)
-- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !
\end{verbatim}
\subsection{Lambda Forms \label{lambda}}