python函数调用时传参方式

位置参数
位置参数需与形参一一对应
def test(a,b) #a,b就是位置参数
    print(a)
    print(b)

test(1,2)
 
关键字参数
与形参顺序无关
def test(x,y)
    print(x,y)
 
test(x=2,y=3)
位置参数必须在关键字参数之前
 
**kwargs:把N个关键字参数,转换成字典格式
1 def test(a,**kwargs)
2     print(a)
3     print(kwargs)
4 test(8,c=1,b=2)
View Code
*args:把N个位置参数,转换成元组
def test(a,*args)
  print(a)   
print(args) test(1,2,3,4,5)
原文地址:https://www.cnblogs.com/shangmo/p/8467870.html