Python map函数

python3中返回迭代器:

函数map

def square(x):
    return x ** 2

r = map(square, [1, 2, 3, 4, 5])

for i in r:
    print(i)

lambda map

r = map(lambda x: x ** 2, [1, 2, 3, 4, 6])

for i in r:
    print(i)

你可能感兴趣的:(Python map函数)