Def show (*arg):
Print (Arg,type (ARG))
Show ([11,22],[33])
Results: ([one, one], []) <class ' tuple ' >
Conclusion: A parameter passed by a * is defined by default as Ganso type
Def show (**arg):
Print (Arg,type (ARG))
Show (k1= ' v1 ', k2= ' v2 ', k3= ' v3 ')
Result: {' K1 ': ' v1 ', ' K3 ': ' V3 ', ' K2 ': ' v2 '} <class ' dict ' > definition
Conclusion: The parameters passed by the two * * numbers are defined by default as dictionary type
Def show (*arg,**kwargs):
Print (Arg,type (ARG))
Print (Kwargs,type (Kwargs))
Show ([11,22,33],[44],[' A ', ' B '],k1= ' v1 ', k2= ' v2 ')
Results:
([One, One, "], [[], [' A ', ' B ']) <class ' tuple ' >
{' K2 ': ' v2 ', ' K1 ': ' v1 '} <class ' Dict ' >
Conclusion: At the same time pass two parameters with the * number, in the formal parameter definition, the first parameter can only be with an * number, the second parameter can only be with two * number, while in the parameter transfer, the first argument can only be a normal definition, the second argument is the definition of a dictionary
Def show (*arg,**kwargs):
Print (Arg,type (ARG))
Print (Kwargs,type (Kwargs))
#show ([11,22,33],[44],[' A ', ' B '],k1= ' v1 ', k2= ' v2 ')
Li = [[11,22,33],[44],[' A ', ' B ']]
Di = {' K1 ': ' v1 ', ' K2 ': ' V2 '}
Show (Li,di)
Show (*li,**di)
Results:
([[One, all,], [] [], [' A ', ' B ']], {' K1 ': ' v1 ', ' K2 ': ' v2 '} ' <class ' tuple ' >
{} <class ' dict ' >
([One, One, "], [[], [' A ', ' B ']) <class ' tuple ' >
{' K1 ': ' v1 ', ' K2 ': ' v2 '} <class ' Dict ' >
Conclusion: By using the first method to pass parameters, Python defaults to a formal parameter that is passed to the first * number, and the second * number does not receive parameters. The second way to pass the arguments is to pass the matching parameters to the corresponding formal parameter.
Python function Dynamic Parameters