What does a double star mean with a variable name in python?

Possible duplicate:
What does ** (double star) and * (star) do for python options?

I am reading the code that was generated by ZSI for python. There is such a line

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

I want to know what it is ** kw neams. Is this type of type a dictionary? Thanks

+7
source share
1 answer

It refers to all keyword arguments passed to a function that is not part of 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'} 

This is similar to using only one asterisk, which refers to all arguments without a keyword:

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

You can combine these (and people often)

 >>> def foobar(*args, **kwargs): ... print args ... print kwargs ... >>> foobar(1, 2, a='3', spam='eggs') (1, 2) {'a': '3', 'spam': 'eggs'} 
+16
source

All Articles