一,例:
二,可以定义多个函数
print(map_test(add,num))可以用匿名函数代替:
print(map_test(lambda x:x+1,num)) 使用这条语句则不需要定义add函数。
注:上述两个代码中的for i in num 这里的num应改为 array
或者:(使用内置map函数,匿名函数):
res=map(lambda x:x+1,num)
print(‘内置函数map,运行结果’,res)
print(list(res))
或者(使用内置map函数,有名函数):
print(‘传的有名函数’,list(map(add,num)))
三,map函数:map(func,array)
第一个位置可以是lambda函数,也可以是自定义函数,第二个位置是可迭代对象,不一定是列表。
四,使用map函数转大写
msg=‘songyue’
print(list(map(lambda x:x.upper(),msg)))