]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
added example for the ** operator in function calls
authorGeorg Brandl <georg@python.org>
Tue, 22 Nov 2005 19:50:22 +0000 (19:50 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 22 Nov 2005 19:50:22 +0000 (19:50 +0000)
Doc/tut/tut.tex

index ae8fcf63cd48c528d5d258853f9f09cf10db461b..fcca54100af945d78676b5c272aa0bb46cd1766e 100644 (file)
@@ -1632,6 +1632,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}}