How to pass a list as a function's arguments

别说谁变了你拦得住时间么 提交于 2019-12-20 07:19:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!