Summary parameter
1, the position parameter
2, the default value of the parameter
3, the dynamic parameters
1, the dynamic transmission parameters * args positional parameters.
The system will automatically positions all the parameters polymerized into a tuple
2, the dynamic parameter passing ** kwargs keyword parameters.
The system will automatically all the parameters of the polymerization into a dictionary keyword
3, def func (* args, ** kwargs): # Invincible parameters
Pass
. 4, the sequence: position parameter, * args, default values, ** kwargs key
5, the above procedure, when in use, can be any mix
4, in the arguments, *, ** represents the break (keywords position parameter or parameters)
on the parameter, *, ** represents the polymerization (or tuples dictionaries)
5, an example of
def func1(*args):
print(args)
func1 (1,2,4,6)
def func2 (* args): # 1 Recommended: a plurality of positional parameters as a list of elements, by * li1- arguments passed to the parameter args *
Print (args)
in Li1 = [1,5,7]
func1 (* li1)
def func3(**kwargs):
print(kwargs)
func3(name='jack',age=18)
def func4 (** kwargs): # 2 Recommended: a plurality of key parameters as elements of the dictionary (key-value pairs) is transmitted to the parameter ** kwargs by ** dic1- argument
Print (kwargs)
DIC1 = { ' name ':' Jack ',' Age ':. 19}
Func4 (DIC1 **)
Dynamic parameters
Parameter:
1, the position parameter
2, the default value of the parameter
3, the dynamic parameters
* args parameter dynamic receive position, the received tuple
** kwargs dynamic receive keyword parameter received dictionary is
def func (* args, ** kwargs ): # parameter
Pass
FUNC (* in Li1) # argument. 1
FUNC (** dic1) # 2 arguments
in the parameter * ** represents polymerized to form (a tuple, dictionary)
on the argument, * and ** indicates broken (iterative deconstruction can, Dictionary deconstruction)
Sequence: - argument
position parameters, * args, default values, ** kwargs key