def python_test(a, *c, b=1, **kwargs): # a为必填参数,c为可选参数,b为默认参数,kwargs为关键字参数 print(a) print(c) print(c[0]) print(b) print(kwargs) return kwargs
调用函数:
python_test(1, 3, 4, b=2, e=1, f=2) print("------------") print(python_test(1, 10, g=1, f=2)['g'])
输出结果如下:
在for循环中使用关键字参数 **kwargs
def number_setting(*num): for a in num: print(a) number_setting(3, 5)
输入结果如下: