首页 > 解决方案 > 为什么我们需要在前面写 list 而使用 map 函数,因为 split() 已经返回了一个列表?

问题描述

a = map(int, input().split())

不使用地图前面的列表给了我以下o/p。有人可以告诉吗?

<map object at 0x7f28ed8a4fa0>

标签: pythonpython-3.xlist

解决方案


map函数将返回一个map可迭代的对象。如果要将其转换为另一个数据结构(list此处),则需要显式执行。

您可以迭代地图对象

for item in map(int, input().split()):
    print(item)

推荐阅读