map()函数
map(func, *iterables) --> map object
Make an iterator that computes the function using arguments from
each of the iterables. Stops when the shortest iterable is exhausted.
有道翻译结果:
”“”
map(func, *iterables)——> map对象
创建一个迭代器,使用来自的参数计算函数
每个迭代器。当最短的迭代器耗尽时停止。
”“”
作用
返回一个迭代器,对iterable的每个项应用function,生成结果。
因为返回值是一个迭代器所以直接打印map()的结果会出现这样的<map object at 0x00000112F878BE80>这是一个map对象
想要输出结果接着往下看
使用for循环遍历输出
num = ['1', '2', '3']
nums = map(lambda x:int(x),num)
for i in nums:
print(i,end=" ")
输出结果为:1 2 3
使用list()转列表输出
num = ['1', '2', '3']
print(list(map(lambda x: int(x), num)))
···
输出结果为:
[1, 2, 3]