当您使用以下语法定义函数时:
def someFunc(*args):
for x in args
print x
您告诉它您需要可变数量的参数。如果你想传递一个列表(来自其他语言的数组),你会这样做:
def someFunc(myList = [], *args):
for x in myList:
print x
然后你可以这样调用它:
items = [1,2,3,4,5]
someFunc(items)
您需要在变量参数之前定义命名参数,在关键字参数之前定义变量参数。你还可以这样:
def someFunc(arg1, arg2, arg3, *args, **kwargs):
for x in args
print x
它需要至少三个参数,并支持可变数量的其他参数和关键字参数。