Return: End Function and return value
No return: Returns none
Number of return values = 1 o'clock: Returns a specific value
The return value is a number + string + list, etc.: Returns a tuple
Need return is required function full call
def test1 (): print (' in the Test1 ') def test2 (): print (' in the Test2 ') return 0 #结束函数并返回0def test3 (): Print (' In the Test3 ') return 1, ' Hello ', [' Alex ', ' Wupeiqi '], {' Name ', ' Alex '} #结束函数并返回0x =test1 () #return返回值可以赋值给变量y =test2 () Z=test3 () print (x) print (y) print (z)
Function parameters:
def test (x, y): print (×) print (y) test #1传给x, 2 to y;x,y called formal parameters (positional parameter); The position of the argument and the argument one by one corresponds; Test (y=1,x=2) # Keyword invocation: independent of the parameter order Test #位置参数调用: Match parameter one by one to test (3,y=2) #既有位置参数调用又有关键字参数调用, call execute def Test ( x , Y, z) by position parameter: print Print (y) print (z) test (3,z=2,y=6) test (3,y=2,6) #关键字参数不能在位置参数前面
Python Learning path: function parameters and calls