The ** operator ambiguous?

Diez B. Roggisch deets at
Mon Jul 16 19:42:51 CEST 2007

Robert Dailey schrieb:
> I noticed that the ** operator is used as the power operator, however
> I've seen it used when passing variables into a function. For example,
> I was researching a way to combine dictionaries. I found that if you
> do this:
> a = {"t1":"a", "t2":"b"}
> b = {"t3":"c"}
> dict( a, **b )
> This combines the two dictionaries. However, I have no idea what the
> ** operator is here. I know that when you specify ** as a parameter in
> a function definition, it represents a dictionary of parameters passed
> in. However, in this example it is NOT being used in a function
> definition. It is being used when passing variables into a function.
> Can someone explain what this means? I looked in the documentation but
> I couldn't find anything.

It's the opposite to the function definition **-operator:

def foo(a=0, b=1):
     print a,b

foo(**{a:100, b:200})

-> 100 200


More information about the Python-list mailing list