Problem:
There are two special situations in the Function Definition of Python: The *, * form.
For example, Def myfun1 (username, * keys) Or Def myfun2 (username, ** keys.
Explanation:
* This parameter is used to pass any parameter without a name. These parameters are accessed in a tuple format.
** It is used to process and pass any parameter with a name. These parameters are accessed by dict. *
Application:
#########################
# "*" Application
#########################
Def fun1 (* keys ):
Print "keys type =" + type (keys)
Print "keys =" + STR (keys)
For I in range (0, Len (KEYS )):
Print "keys [" + STR (I) + "] =" + STR (Keys [I])
Fun1 (2, 3, 4, 5)
Output the following results:
Keys type = <type 'tuple'>
Keys = (2, 3, 'A ')
Keys [0] = 2
Keys [1] = 3
Keys [2] =
#########################
# "**" Applications
#########################
Def fun2 (** keys ):
Print "keys type =" + type (keys)
Print "keys =" + STR (keys)
Print "name =" + STR (Keys ['name'])
Fun2 (name = "VP", age = 19)
Output the following results:
Keys type = <type 'dict '>
Keys = {'age': 19, 'name': 'vp '}
Name = VP