Students who have studied PHP or other languages know that the parameters in PHP are not variable (just a lot of times they can be omitted, because the default values are set for parameters when the function is defined). But that's not true in Python, where Python runs the appearance of variable parameters, which appear in the form of (*ARG,**ARG2).
Let's take a look at this usage today:
For example:
def foo1 (arg1,arg2,key1=1,key2=2,*arg,**keywords):
Print "Arg1 parameters is", arg1
Print "Arg2 parameters is", arg2
Print "Key1 parameter is", Key1
Print "Key2 parameter is", Key2
Print "Arbitrary parameter is", ARG
Print "keywords parameter is", keywords
Foo1 (1,2,3,4,5,6,k1=1,k2=2,k3=3)
Output:
Arg1 parameters is 1
Arg2 parameters is 2
Key1 parameter is 3
Key2 parameter is 4
Arg parameter is (5, 6)
Keywords parameter is {' K3 ': 3, ' K2 ': 2, ' K1 ': 1}
Function parameters are divided into four parts:
Arg1,arg2,key1,key2 General Parameters
*arg non-keyword parameter list
**keywords keyword parameter list
Function reputation part, the four parts of the parameter can not be reversed position, may not have a few parts.
This feature of the Python function makes the function parameters more flexible, and the number of parameters is unrestricted.
Note: This usage is commonly used in the Python adorner, and as for what is an adorner, it is a very important feature in Python and I will explain it later
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/