Variable-length parameters exist in the sense that each time a function is called to handle different amounts of parameter input. That is, the parameter number entered before the call is unknown, or multiple calls to the function, each time the amount of input parameters is inconsistent;
Variable-length parameters are classified as non-keywords and keyword types, corresponding to tuples and dictionaries, defining a class as follows, and the function is to print out the input function:
1>>>classTest:2 defKeyword (self,a,b,*non_keyword,**keyword):3 Print('a is', a)4 Print('b is', B)5 Print('Non_keyword', Non_keyword)6 forKeyinchKeyword:7 Print("'%s ':%s"%(Key,str (Keyword[key] )))8>>> test =Test ()9>>> dis = Test.keyword ('a','b',('C','D'), e='e', f='F')TenA isa OneB isb ANon_keyword (('C','D'),) - 'e': E - 'F': F
When the input is entered at one time, when it is called again, the input of a different number of parameters can still be printed out:
1>>> test0 =Test ()2>>> Dis0 = Test0.keyword ('a','b',('C','D','C0','C1','D0','D1'), e='e', f='F', g='g', h='h')3A isa4B isb5Non_keyword (('C','D','C0','C1','D0','D1'),)6 'h': H7 'e': E8 'F': F9 'g': G
Therefore, variable length parameter input has some flexibility and can be used to deal with different scenarios.
Python variable-length parameters (non-keyword and keyword parameters)