Python **kwargs

任意关键字参数,**kwargs

如果您不知道将传递多少关键字参数到您的函数中,请在函数定义中的参数名之前添加两个星号:**

这样,函数将接收到一个参数字典,并可以相应地访问其中的项:

实例

如果关键字参数的数量未知,请在参数名前添加一个双星号 **

def my_function(**kid):
  print("His last name is " + kid["lname"])

my_function(fname = "Bill", lname = "Gates")

亲自试一试

在 Python 文档中,任意关键字参数(Arbitrary Kword Arguments )通常缩写为 **kwargs

相关页面

教程:

术语: