Possible Duplicate:
What does *args and **kwargs mean?
I’ just reading Mining the social web and encountered a python syntax that I can’t figure out:
transforms = [(', Inc.', ''), (', Inc', ''), (', LLC', ''), (', LLP', '')]
"google, Inc.".replace(*transforms[0])
But if I type
*transforms[0]
in the interpreter, it says it is invalid syntax. I googled it, but the python docu really is not up for the job.
So what does the asterisk means here please? Thank you all.
The
*argumentformat in python means: use all elements in the sequenceargumentand pass them as arguments to the function.In this specific case, that translates to:
This is easiest demonstrated:
You can also use the
**kwdouble star format to pass in keyword arguments:and you can use the same spelling in a function definition to capture arbitrary positional and keyword arguments: