目录

map函数

代码

def add(x):
    return x + 2


a = [2, 3, 4, 6]

print(a)

print(list(map(add, a)))

输出

[2, 3, 4, 6]
[4, 5, 6, 8]