# The value of the default parameter is passed to the function at the beginning of the definition, # will not be modified in the subsequent revisions. # The value of the default parameter must be placed in the last face of the positional parameter argument # The default argument used by the scene is that a parameter does not often become a scene, so the parameters are generally immutable types. String element ancestor number res=1def foo (x,y=res): Print(x, y) res=10foo ("aaa")
#结果是
AAA 1
def foo (x,y,*t): Print(x, y)print(*t) #(3, 4, 5) foo (1,2,3,4,5)
#结果是:
3 4 5
#星会将接受的多余的参数转化为元祖赋值给t
Tenth quarter
#=================== Section Tenth#3. Parameters of the scatterdefFoo (x,y,*t):Print(x, y)Print(t)#foo (1,2,3,4,5)Foo (1,2,*['a','b','C'])#here the *[' a ', ' B ', ' C ' means to break the list into multiple parameters passed to the function.#as soon as you see a star, you're dealing with positional parameters.#4. Variable length parameters#The number of arguments in the call stage is not fixed, so the number of parameters is not fixed#how to resolve a parameter * A star represents an out-of-bounds portion of a positional argument, * * Indicates that the argument passed by the key arguments is out of bounds.#t= (2,3,4)#The star will convert the extra parameters received to the Yuanzu value to TdefFoo (x,y,*t):Print(x, y)Print(t)#foo (1,2,3,4,5)Foo (1,2,*['a','b','C'])#(' A ', ' B ', ' C ')Foo (*['a','b','C','D'])#(' C ', ' d ')#5. The Yuan Zu can alsodeffoo (x, y):Print(x, y) foo (* ())#1 2#6. The agreement commonly known as everyone generally write *args represents the positional parameter **kwargs represents the keyword parameter. Actually, these two words can be written casually, it is customary to write.#keywords no fixed number of wear parametersdefFoo (x,y,**Kwargs):Print(x, y)Print(Kwargs) foo (x=111,y=444,a=11,b=33,c=44,d=55,cc=99,dd=88)## # #字典关键字的参数打散defFoo (x,y,**Kwargs):Print(x, y)Print(Kwargs) foo (**{'a': 11,'b':' A','D': 44,'x': 334,'y': 56})#Keyword Transfer parameter decompressiondeffoo (x, y):Print(x, y) foo (**{'x': 11,'y': 22})#positional parameters and keyword parameters are not fixed parametersdefFoo (*args,**Kwargs):Print(args)#Here's a meta-ancestor . Print(Kwargs)#What you get here is a dictionary.Foo (1,2,3,4,**{'x': 11,'y': 22})(1, 2, 3, 4){'x': 11,'y': 22}#The received parameters are passed intact to the function that was called to the final call.defwrapper (x, Y, z):Print(x, Y, z)defFoo (*args,**kwargs):#encapsulating Cheng Yuanju and dictionariesWrapper (*args,**kwargs)#The parameters that are extracted into each parameter indicate that the received parameters are passed to the final call function intact.Foo (1,y=2,z=3)#7. The named keyword parameter represents the parameter that is defined after the *, and the parameter must be passed. Must be a value of key value in the form of a pass.#* The following y and Z are named keyword parametersdefWrapper (x,*, y,z):Print(x, y, z) wrapper (1,Y=2,Z=3)
Python third week file handling and functions