问题
If I have a function:
def run(time, message, time_span_pattern):
...
And a list like:
run_args = ['1s', '1 second alarm', <_sre.SRE_Pattern object at 0x100435680>]
How can I pass the list, as separate arguments, to run? Is there a builtin way to do this, or am I forced to reference each element individually and by index?
回答1:
You're looking for:
run(*run_args)
This is explained in more detail in this StackOverflow answer about the star and double star operator
It's also covered in the python docs
来源:https://stackoverflow.com/questions/41501222/how-to-pass-a-list-as-a-functions-arguments