Python 函数参数主要分为3种形式:
1.位置或关键字参数
2.任意数量的位置参数
3.任意数量的关键字参数
def fun7(a,b,c): print a,b,c fun7(1,8,9) fun7(a=89,c=70,b=99) fun7(a="soyo",c=100,b="soyosoyo") def fun8(str2,*num): print "字符串为:"+str2 print "数字为:",num return num q=fun8("soyo5",1,2,6,8) for i in q: print i def fun9(str3,*num1,**kwargs): print "str3="+str3 print "元组内的数字为:",num1 print "字典为:",kwargs return kwargs a1=fun9("soyo100",1,5,9,name="小米",value=88) keys=a1.keys() print keys for i in keys: print a1[i]
结果:
1 8 9
89 99 70
soyo soyosoyo 100
字符串为:soyo5
数字为: (1, 2, 6, 8)
1
2
6
8
str3=soyo100
元组内的数字为: (1, 5, 9)
字典为: {‘name‘: ‘\xe5\xb0\x8f\xe7\xb1\xb3‘, ‘value‘: 88}
[‘name‘, ‘value‘]
小米
88