当前位置: 移动技术网 > IT编程>脚本编程>Python > python中map函数

python中map函数

2018年12月08日  | 移动技术网IT编程  | 我要评论

白鱼,中国石化加油卡积分查询,耽恋依依

map函数形参为一个函数和一个迭代对象

给定一个列表,实现加1

l = [1, 2, 3, 4, 5]

res = map(lambda x:x+1, l)

print(list(res))

# 不使用map函数,实现的效果是一模一样的
def add_test(x):
  return x+1

def map_test(func, array):
  temp = []
  for i in array:
    res = func(i)
    temp.add(res)
  return temp

res = map_test(add_test, l)
print(res)

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网