The difference between * and ** python mass participation of

  1. def f (* a), the def f (* a) is transmitted in the form of list or tuple, the tuple is in the form of an internal function to process, so when the call, need to assemble a list or tuple, input according to a single digital processing such tuple. Defined and variable parameters list or tuple define parameters compared, only the front of the parameter plus a *number. Inside the function, the parameter numbersreceived is a tuple, and therefore, the function code is completely intact. However, when you call the function, you can pass any number of parameters, including 0 parameter.
  2. In the def f (** a), the variable parameter allows you pass 0 or any number of parameters , these parameters are automatically assembled as a variable in the tuple function call. The key parameter allows you pass 0 or any number of parameters including the parameter name , these keyword parameters are automatically assembled into a dict inside the function.
  3. Two types of simplified method: * a form
    >>> nums = [1, 2, 3]
    >>> calc(*nums)
    14

     

  4. ** a form
    >>> kw = {'city': 'Beijing', 'job': 'Engineer'}
    >>> person('Jack', 24, **kw)
    name: Jack age: 24 other: {'city': 'Beijing', 'job': 'Engineer'}

    Reference article: https://www.cnblogs.com/gongyu2018/p/8805183.html

2019-09-09  21:17:54

Guess you like

Origin www.cnblogs.com/ybl20000418/p/11494324.html