使用以下语法定义函数时:
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
至少需要三个参数,并支持其他参数和关键字参数的可变数量。



