python之函数参数 夏至未至

#参数,默认参数,可变参数,关键字参数
def test(p1,p2=20,*args,**kwargs):
print("第一个参数是:%s"%p1)
print("第二个参数是:%s"%p2)
print("第三个参数是:{}".format(args))
print("第四个参数是:%s"%kwargs)
#test(1,2,3,4,name='boony',age='18')
输出:

第一个参数是:1
第二个参数是:2
第三个参数是:(3, 4)
第四个参数是:{'name': 'boony', 'age': 18}

备注:可变参数作为元组返回如(3,4)

原文地址:https://www.cnblogs.com/maisha/p/15708035.html