Python 3.x--函数的参数问题
-------------------参数类型-----------------
1、位置参数
def fun1(x,y):
print(x)
print(y)
return 0
fun1(1,3)
2、关键字参数
def fun1(x,y):
print(x)
print(y)
return 0
fun1(y=1,x=3)
3、位置参数、关键字参数、默认参数使用
def fun1(x,y=6):
print(x)
print(y)
return 0
fun1(10)
fun1(10,7)
fun1(x=8)
4、参数组
*arge-------------------------
def fun1(x,*args):
print(x)
print(args)
return 0
fun1(1,3,15,1,3,4)
fun1(1,*(3,15,1,3,4))
*kwarge-------------------------
def fun1(x,**kwargs):
print(x)
print(kwargs)
return 0
fun1(1,name = 'Harry',age = 18)
fun1(1,**{name:'Harry',age:18})
混合使用
def fun1(x,y,age=17,*args,**kwargs):
print(x)
print(y)
print(args)
print(kwargs)
return 0
fun1(1,3,15,1,3,4,name = 'Marry',sex = 'M')