First, function return value
function return value if it is multiple strings, numbers, lists, dictionaries, a tuple is returned, as follows
deftest1 ():Passdeftest2 ():#print ("Hello test2") return0deftest3 ():#print (' Hello test3 ') return1,10,['AAA', 111],{1:'www'}x=test1 () y=test2 () z=test3 ()Print(x)Print(y)Print(z)
Return results >>>>None0 (1, ['aaa'www'})
function parameter position and pass value:
def test4 (x, y ): Print (x) Print (y) def test5 (x, y , z): Print (x) Print (y) Print (z) test4 (y=1,x=2) # test4 (2,y=1) #这样也是可以的test5 (3,z=1,y=2)
return result >>>21321
Second, function parameters
defTest1 (*args):#Accept n Positional arguments, convert to tuple output Print(args) test1 (1,2,3,4)defTest4 (X,*args):#assigns the first value of the argument to X, and the remaining value to args, to the tuple output Print(x)Print(args) test4 (1,2233,4,5)defTest2 (* *Kwargs):Print(Kwargs) test2 (name='yuqing', age=' -')defTest3 (Name,*args,**kwargs):#convert n keyword arguments to a dictionary Print(name)Print(args)Print(Kwargs) test3 ('yyuqing', 1,2,sex='m', age=27)
Back to Results >>>(1, 2, 3, 4)1(2233, 4, 5){' Age':' -','name':'yuqing'}yyuqing (1, 2){' Age': 27,'Sex':'m'}
Functions of Python