The second parameter function

A named parameter keywords : function definition when, after the parameter * parameter, referred to as key parameter name, parameter which can only receive traditional values of the key argument.

DEF FUNC (A, B, *, x, y):   # A, B for the location parameter * is a variable length parameter, x, y for the key parameter named 
    Pass 
FUNC ( . 1, 2,. 1 = X , y = 2)  

Second, the combination of parameters

  1, the parameter order of mixing: a position parameter, default parameter, * args, parameter name keyword, the keyword default parameter, ** kwargs.

def func(a, b=2, *args, x, **kwargs):
    pass
func(1, 3, 4, 5, x=6, y=7, z=8)  # a=1 args=(4, 5) x=6,kwargs={'y': 7, 'z': 8}

  2, the order of mixing arguments: Location argument, the argument may traverse *, Keyword argument, argument * dictionary.

def func(a, b, c, d, e, f):
    pass
func(1, *(2, 3), d=4, **{'e': 5, 'f': 6})  # a=1,b=2,c=3,d=4,e=5,f=6

 

Guess you like

Origin www.cnblogs.com/caoyu080202201/p/12524266.html