Python args kwargs 技巧
程序员文章站
2022-03-08 20:10:04
```
def f(*args): print(args) a=[1, 2, 3]
f(a)
f(*a) 运行结果:
([1, 2, 3],)
(1, 2, 3)
``` ```
def f(**kwargs): print(kwargs) f(name='klvchen', age=28)
f(*... ......
def f(*args): print(args) a=[1, 2, 3] f(a) f(*a) 运行结果: ([1, 2, 3],) (1, 2, 3)
def f(**kwargs): print(kwargs) f(name='klvchen', age=28) f(**{'name':'klvchen', 'age': 28}) 运行结果: {'name': 'klvchen', 'age': 28} {'name': 'klvchen', 'age': 28}
上一篇: python中 is 与 == 的区别