映射函数map

映射函数map

语法: map(function, iterable)

迭代对象中 的每一个元素进行映射, 分别执行function函数

例子:  ls =[1,2,3,4,5,6]

def func(e):

    return e*e

mp = map(func,ls)    # 把列表ls中的每一个元素传递给func, 映射,一一对应, 返回执行的结果

    # print(mp)

print(list(mp))

   ,,,

猜你喜欢

转载自www.cnblogs.com/jack20181017/p/9911909.html