欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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}