python中的可变长参数有两种:
一种是非关键字参数(*元组),另一种是关键字参数(**字典)
非关键字可变长参数:
"""非关键字可变参数,一个星号作为元组传入函数"""def function(*args): for i in args: print(i) return argsprint(function(1,2,3,4,5,6))#输出:123456(1,2,3,4,5,6)
关键字可变参数:
"""关键字可变参数,两个星号作为字典传入函数"""def function(**args): for i in args.keys(): print(args[i]) return argsprint(function(a=1,b=2,c=3,d=4,e=5,f=6))#输出:123456{ "a":1,"b":2,"c":3,"d":4,"e":5,"f":6}