I have a function:
def greeter(name, greeting, punc):
print greeting+', '+name+punc
I have a dictionary with parameters:
params={'name':'Mark','greeting':'How are you','punc':'?'}
When I call the function as greeter(**params), I get the expected output How are you, Mark?. But When I call like this greeter(*params), I get the output name, puncgreeting. Looks like a list of keys from params has been passed to greeter. What is actually happening here?
Just curious.
That is indeed what is happening, more or less.
*xexpectsxto be an iterable, and iterates over it, interpreting the results as arguments one by one. Iterating over a dict, by default, iterates over its keys. (You could get name/value pairs instead, for example, withgreeter(*(params.items())), but the dict would still be unsorted so order of iteration would be unreliable.)