标签:first form def **kwargs *args pytho nbsp usr print
#!/usr/bin/env python
def foo(*args,**kwargs):
print(‘args: {0}‘.format(args))
print(‘kwargs {0}‘.format(kwargs))
foo(1,2,3,a=‘first‘,b=‘second‘)
运行结果:
args: (1, 2, 3) #位置参数是一个元组
kwargs {‘b‘: ‘second‘, ‘a‘: ‘first‘} #关键字参数是一个字典
python 位置参数和关键字参数 *args **kwargs
标签:first form def **kwargs *args pytho nbsp usr print
原文地址:https://www.cnblogs.com/hixiaowei/p/9044700.html