what does double star followed by variable name mean in python?

Possible Duplicate:
What does ** (double star) and * (star) do for python parameters?

I am reading some code that been generated by ZSI for python. There is a line like this

def verifyVehicle(self, request, **kw): ....

I want to know what does this **kw neams. Is this neam a dictionary type? Thanks


It refers to all keyword arguments passed to the function that aren't in the method definition. For example:

>>> def foo(arg, **kwargs):
...     print kwargs
... 
>>> foo('a', b="2", c="3", bar="bar")
{'c': '3', 'b': '2', 'bar': 'bar'}

It is similar to just using one asterisk, which refers to all non-keyword arguments:

>>> def bar(arg, *args):
...     print args
... 
>>> bar(1, 2, 3, 'a', 'b')
(2, 3, 'a', 'b')

You can combine these(and people often do)

>>> def foobar(*args, **kwargs):
...     print args
...     print kwargs
... 
>>> foobar(1, 2, a='3', spam='eggs')
(1, 2)
{'a': '3', 'spam': 'eggs'}
链接地址: http://www.djcxy.com/p/9062.html

上一篇: 将参数列表传递给Python函数

下一篇: python中的变量名是什么意思?