2019-04-19
阅读量:
488
如何理解* kwargs函数
python中函数定义中的特殊语法** kwargs用于传递一个keyworded,variable-length参数列表。我们使用名称kwargs和双星。原因是因为双星允许我们传递关键字参数(以及它们中的任意数量)。
- 关键字参数是在将变量传递给函数时为变量提供名称的位置。
# Python program to illustrate
# *kargs for variable number of keyword arguments
def myFun(**kwargs):
for key, value in kwargs.items():
print ("%s == %s" %(key, value))
# Driver code
myFun(first ='Geeks', mid ='for', last='Geeks')
输出:
last == Geeks
mid == for
first == Geeks






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论