function return multiple values:
Supplementary Knowledge Points: Write code to get less use of global variables:
1. Unsafe
2. Will always occupy the memory does not release
function multiple return values, the return values are placed in a tuple and returned
1 def Hello (a,b,c,d): 2 return a,b,c,d 3 Res=hello ( " YBQ , " ede , " RFV , " deq " ) 4 print (res) # (' Ybq ', ' Ede ', ' Dede ', ' DEQ ')
List Deduction formula:
1 #List-derived2nums=[0,1,3,4,5,6,7]3 #Convert the nums int type to a string, method one:4new_nums=[]5 forNinchNums:6n=str (n)7 new_nums.append (n)8 Print(new_nums)#[' 0 ', ' 1 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ']9 #Convert the nums int type to a string, method two:TenNEW_NUMS=[STR (N) forNinchNums#List-derived conversions, simplifying code One Print(new_nums)#[' 0 ', ' 1 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ']
Exchange values for two variables:
1 method One:2A=13b=24tmp=05tmp=a6A=b7b=tmp8 Print(A, B)#2,19 Ten Method Two: OneA=1 Ab=2 -B,a=A, b - Print(A, B)#for Python 2,1 the - Method Three: -A=1 -b=2 +a=a+b -b=a-b +A=a-b#Add and Subtract methods Exchange two variable values
Python Learning Notes (eight) function return multiple values, list deduction and exchange values of two variables