1 def add(x,y): 2 print(x+y) 3 #return x+y 4 x = [1,2,3] 5 y = [4,5,6] 6 print('type(zip(x,y)):',type(zip(x,y)))#zip class 7 print('for i,j in zip(x,y)') 8 for i,j in zip(x,y): 9 print(i+j) 10 print('for i,j in [(1,5),(2,6),(3,7)]') 11 for i,j in [(1,5),(2,6),(3,7)]: 12 print(i+j) #print 6,8,10 13 def gen(func,a,b): #a,b为列表 14 for item1, item2 in zip(a,b): 15 yield func(item1,item2) 16 print('for i in gen(add,x,y)') 17 print('type(gen(add,x,y):)',type(gen(add,x,y)))#generator class 18 for i in gen(add,x,y): #把func结果一次次迭代出来 19 20 i #print 5,7,9 21 #print(i) 22 result = map(lambda x,y:print(x+y),x,y)#返回元素为lambda结果的迭代器类 23 print('for i in map(lambda x,y:print(x+y),x,y)') 24 for i in result: 25 i 26 #print(i)#用于map(lambda x,y:x+y,x,y)View Code