def fun(*args, **kwargs):
print(‘args=’, args)
print(‘kwargs’, kwargs)
fun(1,2,3,4, A=‘a’, B=‘b’, C=‘c’, D=‘d’)
def fun(name, *args):
print(‘你好:’, name)
for i in args:
print(“你的宠物有:”, i)
fun(“Geek”, “dog”, “cat”)
def fun(**kwargs):
for key, value in kwargs.items():
print("{0} like {1}".format(key,value))
fun(Geek=“cat”, cat=“box”)
形参的时候是定义函数,让函数知道这个参数是什么类型
def fun(data1, data2, data3):
print(“data1:”,data1)
print(“data2:”,data2)
print(“data3:”,data3)
args = (“one”,2,3)
fun(*args)
kwargs = {“data1”:1,“data2”:2,“data3”:3}
fun(**kwargs)
实参的时候是对传入的实参进行解引用,这个时候函数的形参是定长
参考:https://blog.csdn.net/yilovexing/article/details/80577510