我正在使用Python试图找出一个关键词,我看到了单词" kwargs",我知道这是在被调用函数中的某种参数,但我无法找到它在任何地方的含义或代表.
例如,Python文档中的这个条目说......
read_holding_registers(address, count=1, **kwargs)
Run Code Online (Sandbox Code Playgroud)
address – The starting address to read from
count – The number of registers to read
unit – The slave unit this request is targeting
Run Code Online (Sandbox Code Playgroud)
它看起来像是指向指针的引用,但这就是我能说的全部......
这甚至不在**kwargs参数列表中使用" "它使用我看起来像" unit"而不是" kwargs"的东西.
我似乎找不到任何kwargs意味着什么.
也许这是"关键词论证"?我在这里错过了什么?
这里的任何想法都有帮助?谢谢 !短发
the*_*eye 12
**kwargs表示关键字参数.它实际上不是一个python关键字,它只是一个人们遵循的约定.这将获得传递给函数的所有键值参数.例如,
def func(*args, **kwargs):
print args, kwargs
func(1, "Welcome", name="thefourtheye", year=2013)
Run Code Online (Sandbox Code Playgroud)
将打印
(1, 'Welcome') {'name': 'thefourtheye', 'year': 2013}
Run Code Online (Sandbox Code Playgroud)