num_1=[1,2,10,5,3,7] # num_2=[] # for i in num_1: # num_2.append(i**2) # print(num_2) # def map_test(array): # num_2=[] # for i in num_1: # num_2.append(i**2) # return num_2 # # ret=map_test(num_1) # print(ret) num_1=[1,2,10,5,3,7] #lambda x:x+1 #def add_one(x): #return x+1 #lambda x:x-1 def reduce_one(x): return x-1 #lambda x:x**2 def pf(x): return x**2 #最终结果 def map_test(func,array):#num_1=[1,2,10,5,3,7] num_2=[] for i in array: res=func(i)#lambda匿名函数 num_2.append(res) return num_2 #print(map_test(add_one,num_1)) print(map_test(lambda x:x+1,num_1)) # print(map_test(lambda x:x-1,num_1)) # print(map_test(lambda x:x**2,num_1)) #Print (map_test (reduce_one, NUM_1)) # Print (map_test (PF, NUM_1)) # the Map built-in function NUM = the Map ( the lambda the X-: the X-+ 1, NUM_1) # pass an anonymous function, map function default will be iterative parameter iterative operations, and operation parameters used for each of the foregoing functions, and returns a map iterable Print (type (NUM)) # for I in NUM: # Print (I) Print (List (NUM)) # pass a custom function Print (List (the Map (reduce_one, NUM_1))) # parameters First, the function expression parameter 2 is iterables msg = " linhaifeng " MEA = List (the Map ( the lambda the X-: x.upper ( ), msg)) Print (MEA)