Single and double asterisks preceding variables in function arguments
Duncan Booth
me at privacy.net
Mon Jan 26 12:40:49 EST 2004
anton muhin <antonmuhin at rambler.ru> wrote in news:bv3gdg$ms0sn$1 at ID-
217427.news.uni-berlin.de:
> Stephen Boulet wrote:
>> I've run across code like "myfunction(x, *someargs, **someotherargs)",
>> but haven't seen documentation for this.
>>
>> Can someone fill me in on what the leading * and ** do? Thanks.
>>
>> Stephen
>
> See item 7.5 in Language Reference. In short: * declaries list of
> additional parameters, while ** declares map of additional parameters.
> Try somehting like:
>
> def foo(*params): print params
>
> and
>
> def bar(**params): print params
>
> to find out details.
I may be wrong, but I think the OP was asking about calling functions
rather than defining them. The '*' and '**' before arguments in function
calls are described in section 5.3.4 of the language reference but, so far
as I know, isn't explained clearly in any of the more 'user level' text.
There is a brief mention in the library reference under the documention of
'apply'.
In a call of the form:
myfunction(x, *someargs, **someotherargs)
the sequence 'someargs' is used to supply a variable number of additional
positional arguments. 'someotherargs' should be a dictionary and is used to
supply additional keyword arguments.
More information about the Python-list
mailing list