passing a variable argument list to a function

Christian Heimes lists at cheimes.de
Tue Aug 12 20:35:17 EDT 2008


Scott wrote:
> I suspect there's a simple bit of syntax that I'm missing -- can
> anyone give me a hand?

Yeah. It's so easy and obvious that you are going to bang your head 
against the wall. :) The single star does not only collect all arguments 
in a function definition. It also expands a sequence as arguments.

def egg(*args):
     spam(*args)

somefunc(*(a, b, c)) is equivalent to somefunc(a, b, c).

Double star (**) does the same with keyword arguments

Christian




More information about the Python-list mailing list