map() 是python的内置函数,会根据提供的函数对指定序列做映射。
对可迭代函数*iterables中的每个元素应用func方法,将结果作为迭代器对象返回。...注意:map()函数返回的是一个新的迭代器对象,不会改变原有对象
map()用法
class map(object)
| map(func, *iterables) --> map object...案例一
# 计算平方数
def square(x):
return x * x
obj = map(square, [1, 2, 3])
print(type(obj), obj)
print(list...'> map object at 0x0000023BC9B59D88>
[1, 4, 9]
Process finished with exit code 0
案例二
# 使用 lambda 匿名函数计算平方数...square = map(lambda x: x ** 2, [1, 2, 3, 4, 5])
print(square, list(square))
C:\Users\admin\AppData\