In fact, the key is * and **
We have three examples to explain:
General parameters:
DEF test1 (Arg): Print (Arg) test1 ( " A " ) Output: A
* The remaining parameters is represented by Ganso
def test1(arg1,arg2,*args): print(arg1) print(arg2) print(args) test1(1,2,3,"a","b") 输出: 1 2 (3, 'a', 'b')
** parameter is converted into dictionary indicates
DEF test2 (** kwargs): Print (kwargs) test2 (A =. 1, B = 2 ) Output: { ' A ' :. 1, ' B ' : 2}
Finally, we must combine three ways :( Note that the order)
def test4(arg1,arg2,*args,**kwargs): print(arg1) print(arg2) print(args) print(kwargs) test4(1,2,3,4,5,a=1,b=2) 输出: 1 2 (3, 4, 5) {'a': 1, 'b': 2}