问题描述:
l1=[i for i in range(10)]
def mulu(n):
return n*10
l3=map(mulu,l1)
print(l3)
<map object at 0x0000018323F3A6D8>在python3.x版本中无法正常返回列表,只能返回类型
问题解决:
1.使用 for in 拆开后合并起来
l1=[i for i in range(10)]
def mulu(n):
return n*10
l2=[]for i in l1:
l2.append(i*10) #把l1乘以10后添加到l2里面
print(l2)
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
2.使用list()
1 l1=[i for i in range(10)]
2 def mulu(n):
3 return n*10
4 l3=map(mulu,l1)
5 print(list(l3))
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]