python_内置函数map()

1、map(square, [x,y,z,m]) >>> 将列表中的元素依次传递给函数square。
map() 会根据提供的函数对指定序列做映射,生成一个迭代器,需要list()将其转换成列表

def square(x):
    return x ** 2
print(map(square, [1,2,3]))
print(list(map(square, [1,2,3] )))

C:\Python39\python.exe D:/se_frame/Cases/MapAaaCases/test_3.py
<map object at 0x00000245B05B8FA0>【这里是迭代器】
[1, 4, 9]

2、

猜你喜欢

转载自blog.csdn.net/weixin_45451320/article/details/115145816
今日推荐