Python - 使用列表作为函数参数 [英] Python - use list as function parameters
本文介绍了Python - 使用列表作为函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 Python 列表(例如 params = ['a',3.4,None]
)作为函数的参数,例如:
How can I use a Python list (e.g. params = ['a',3.4,None]
) as parameters to a function, e.g.:
def some_func(a_char,a_float,a_something):
# do stuff
推荐答案
您可以使用 splat 运算符执行此操作:
You can do this using the splat operator:
some_func(*params)
这会导致函数将每个列表项作为单独的参数接收.这里有一个描述:http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists
This causes the function to receive each list item as a separate parameter. There's a description here: http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists
这篇关于Python - 使用列表作为函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文