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
In a function definition, the double asterisk is also known **kwargs. They used to pass a keyword, variable-length argument dictionary to a function. The two asterisks (**) are the important element here, as the word kwargs is conventionally used, though not enforced by the language.
The asterisk (star) operator is used in Python with more than one meaning attached to it. For numeric data types, * is used as multiplication operator >>> a=10;b=20 >>> a*b 200 >>> a=1.5; b=2.5; >>> a*b 3.75 >>> a=2+3j; b=3+2j >>> a*b 13j.
After you have found each of the stars listed here, move onto the Astronomical League's Double Star Club checklist of targets. Variable stars. Like double stars, variable stars are not as adversely affected by light pollution as some other sky targets are.
Python has *args which allow us to pass the variable number of non keyword arguments to function. In the function, we should use an asterisk * before the parameter name to pass variable length arguments.
What does the Double Star operator mean in Python? For numeric data types double asterisk (**) is defined as exponentiation operator In a function definition, argument with double asterisks as prefix helps in sending multiple keyword arguments to it from calling environment
For numeric data types double asterisk (**) is defined as exponentiation operator In a function definition, argument with double asterisks as prefix helps in sending multiple keyword arguments to it from calling environment What does the Star operator mean in Python?
In Python function, an argument with single asterisk (star) prefixed to it helps in receiving variable number of argument from calling environment. Argument with double asterisks (stars) is used in function definition when variable number of keyword arguments have to be passed to a function.
In Python function, an argument with single asterisk (star) prefixed to it helps in receiving variable number of argument from calling environment Argument with double asterisks (stars) is used in function definition when variable number of keyword arguments have to be passed to a function
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'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With