Exchange values for two variables
A = 2= 1= 1 A = 2# Way One:# swap values for two variables print(A, b) # Way two:a = a + b #3b = a #2a = A- #3-2
#列表推导式
Nums = [0,1,3,4,5,6,7 for in nums]print(new_nums)
Return multiple values
If the function has more than one return value, the values of the return will be placed in a tuple and returned
def Hello (a,b,c,d): return = Hello ('ybq','mpp','zhx ','lby')print(res)
function is variable
defAdd ():Print('Add Item')defview ():Print('View Products')defDelete ():Print('Delete Item') Choice= Input ('Please enter select 1, 2, 3,'). Strip () menu= { '1': Add,'2': View,'3':d elete}ifChoiceinchMenu:menu[choice] ()#suitable for functions that have no arguments, or where the parameters are the same. Else: Print('Input Error')
Built-in functions
#len type print input strPrint(All ([1, 2, 3, 4]))#determine if the values in an iterative object are truePrint(Any ([0, 1, 2, 3, 4]))#determines whether the value inside an object that can be iterated has a truePrint(Bin (100))#Decimal Turn binaryEjz = Bin (100)Print(Ejz.replace ('0b',"'))#Binary is the beginning of the 0b, using the replacement to remove the 0bPrint(Chr (65))#print the ASCII corresponding to the numberPrint(Ord ('A'))#Print the ASCII code corresponding to the stringPrint(dir (1))#to print a callable method of an incoming objectPrint(Filter (Lambdax:x > 5, [12, 3, 12, 2, 1, 2, 35])#Filter The following iteration objects according to the previous methodPrint(Map (Lambdax:x > 5, [1, 2, 3, 4, 5, 6])#print them all according to the expression#Zipids= [1,2,3,4,7,8,0,-1]names=['Little Black','Small white','Xiao Huang','Little Green']names1=['Little Black','Small white','Xiao Huang','Little Green'] forId,name,sinchZip (ids,names,names1):Print(id,name,s)Print(Sorted ('0123450'))#AscendingPrint(Sorted (ids,reverse=true))#DescendingRound (1.987123,5)#Keep several decimals
Python learning Note (ix)-function 2