Function params with **? what do these mean?

Aahz aahz at pythoncraft.com
Mon Mar 20 18:45:36 EST 2006


In article <r56u12pb4ajvhshvh40slb80di1bfeiagr at 4ax.com>,
Dave Hansen  <iddw at hotmail.com> wrote:
>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

Personally, I think it's a Good Idea to stick with the semi-standard
names of *args and **kwargs to make searching easier...
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis



More information about the Python-list mailing list