(Note: This article is part of the content from the Internet, due to the author's limited, shortcomings, but also hope to comment.) )
mid-Autumn night, slightly cool, but always can't see the moon.
I think, it must be shy, quietly hide behind the clouds.
Well, that's it, I'm so damn witty.
Text:
Note: The 11.6 variable length parameters of the Python Core programming 2nd edition are described in more detail---chapters.
First, the use of *args method
*args is used to package parameters into a tuple to call the function body
Example one:
def function (*args): print(args, type (args)) function (1)
The output results are shown in tuples:
Example two:
def function (x, y, *args): Print(x, y, args) function (1, 2, 3, 4, 5)
Output Result:
Second, the use of **kwargs method
**kwargs Package keyword parameter into dict to function body call
Example one:
def Function (* *Kwargs) :print(Kwargs, type (Kwargs)) function (a=2)
The output is displayed as a list:
Example two:
def Function (* *Kwargs) :print(Kwargs) function (a=1, b=2, c=3)
Output Result:
Note: The position of the parameter arg, *args, and **kwargs three parameters must be certain. Must be (Arg,*args,**kwargs) this order, or the program will error.
def function (arg,*args,**kwargs): print(arg,args,kwargs) function ( 6,7,8,9,a=1, b=2, c=3)
Output Result:
Oops, finished.
Mid-Autumn Festival, think more, want to mention a pot of wine about a few old friends driving a leaf boat,
Lost in the hometown of Jiangnan Water village. The boat swung clear and lakes over the waves.
The difference between *args and **kwargs in Python