Function params with **? what do these mean?
Dave Hansen
iddw at hotmail.com
Mon Mar 20 16:11:17 EST 2006
On 20 Mar 2006 12:46:43 -0800 in comp.lang.python, "J Rice"
<rice.jeffrey at gmail.com> wrote:
>I'm sorry for such a basic question, but I haven't been able to phrase
>a search that gets me an answer and my books are totally silent on
>this. I have seen a number of python function defs that take
>parameters of the form (**param1). Looks like a pointer... but my
>books on python (basic as they are) don't make a mention. What is
>this?
It's a way of accepting a varying number of named arguments. In the
function, the parameter becomes a dictionary with parameter names as
the keys corresponding to the passed parameter values.
It's harder to explain than understand. Try playing with the
following function in the python interpreter:
def test(a,b='b', *c, **d):
print a,b,c,d
A couple suggestions for tests:
test(1,2,3,4)
test(a=1,b=2,c=3,d=4)
test(2,4,6,8,10,12,ralph=23,tony=45)
See what happens. Should be mostly self-explanatory.
Regards,
-=Dave
--
Change is inevitable, progress is not.
More information about the Python-list
mailing list