When the function encounters an indeterminate number of parameters, does the swelling break? *args and **kwargs come to report!
*args **kwargs
When the parameters of a function are indeterminate, you can use *args and **kwargs,*args without a key value, **kwargs has a key value.
>>>def Fun_var_args (Farg, *args):
>>> print "arg:", Farg
>>> for value in args:
>>> print "Another arg:", value
>>>fun_var_args (1, "one", 3) # *args can be used as a list that can accommodate multiple variables
Result
Arg:1
Another arg:two
Another arg:3
**kwargs:
>>>def Fun_var_kwargs (Farg, **kwargs):
>>> print "arg:", Farg
>>> for key in Kwargs:
>>> print "Another keyword ARG:%s:%s"% (key, Kwargs[key])
>>>fun_var_kwargs (farg=1, myarg2= "one", myarg3=3) # myarg2 and Myarg3 are considered key, feeling **kwargs can be used to accommodate multiple keys and valu E's Dictionary
Result
Arg:1
Another keyword Arg:myarg2:two
Another keyword Arg:myarg3:3
Python, I learned from scratch t^t D7