arg对应多出来的位置参数,把它们解析成tuple;kwargs把关键字参数解析成dict. def example(pram): print(pram) def example2(param, *args, **kwargs): print(param) if args: print(args) if kwargs: print(kwargs) #一个不设定参数个数的加法函数 def sum(*args): sum = 0 for a in args: sum += a return sum…
在python中,这两个是python中的可变参数,*arg表示任意多个无名参数,类型为tuple;**kwargs表示关键字参数,为dict. # *允许你传入0个或任意个参数,这些可变参数在函数调用时自动组装为一个tuple. def f(a,*args): print(args) f(1,2,3,4) def calc(*numbers): sum = 0 for n in numbers: sum = sum + n * n print(sum) calc(1,2,3,4) # **,关…