* operator--as in *args?

7stud bbxx789_05ss at yahoo.com
Sun Mar 18 21:07:49 EDT 2007


On Mar 18, 3:40 pm, "Dustan" <DustanGro... at gmail.com> wrote:
> For example:
> aFunction(*(1,2,3))
> is equivalent to:
> aFunction(1,2,3)
>

That's the context I've seen it in, but written like this:

someFunc(*args)

I played around with it a little bit, and it appears the * operator
unpacks a list, tuple, or dictionary so that each element of the
container gets assigned to a different parameter variable.  Although
with a dictionary, only the keys appear to be assigned to the
parameter variables, e.g.:

def g(a,b,c):
        print a, b, c

dict = {"x":10, "y":20, "z":30}
g(*dict)

Is that right?






More information about the Python-list mailing list