In a function call, the single star turns a list into seperateseparate arguments (e.g. zip(*x)
is the same as zip(x1, x2, x3)
ifgiven x=[x1,x2,x3]
) and the double star turns a dictionary into seperateseparate keyword arguments (e.g. f(**k)
is the same as f(x=my_x, y=my_y)
ifgiven k = {'x':my_x, 'y':my_y}
.
In a function definition, it's the other way around: the single star turns an arbitrary number of arguments into a list, and the double start turns an arbitrary number of keyword arguments into a dictionary. E.g. def foo(*x)
means "foo takes an arbitrary number of arguments and they will be accessible through the list xx
(i.e. if the user calls foo(1,2,3)
, x
will be [1(1, 2,3] 3)
)" and def bar(**k)
means "bar takes an arbitrary number of keyword arguments and they will be accessible through the dictionary kk
(i.e. if the user calls bar(x=42, y=23)
, k
will be {'x': 42, 'y': 23}
)".