Problem:
There are two special cases in the function definition of Python, that is, the form of *,** appears.
such as: Def myfun1 (username, *keys) or Def myfun2 (username, **keys) and so on.
Explain:
* Used to pass any of the parameterless parameters, which are accessed in the form of a tuple.
* * Used to process the passing of any parameter with a name, these parameters are accessed using Dict. *
Application:
#########################
# Application of "*"
#########################
>>> def fun1 (*keys):
.. print "Keys type=%s"% type (keys)
... print "keys=%s"% str (keys)
... for I in range (0, Len (keys)):
... print "keys[" + str (i) + "]=%s"% str (keys[i])
...
>>> fun1 (2,3,4,5)
Output the following results:
Keys type=
Keys= (2, 3, 4, 5)
keys[0]=2
Keys[1]=3
Keys[2]=4
Keys[3]=5
#########################
# Application of "* *"
#########################
>>> def fun2 (**keys):
.. print "Keys type=%s"% type (keys)
... print "keys=%s"% str (keys)
... print "name=%s"% str (keys[' name '])
...
>>>
>>> fun2 (name= "VP", age=19)
Output the following results:
Keys type=
keys={' age ': +, ' name ': ' VP '}
Name=vp
"Python" * and * * parameter issues