python 2 的 map 返回 list
python 3 的 map 返回 “(可迭代)map 类”
Python 3.2.3 (default, Feb 20 2013, 17:02:41)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = map(int, input().split())
23 -4 9 0 -31 39 4
>>> b = list(a)
>>> b
[23, -4, 9, 0, -31, 39, 4]
>>> a
<map object at 0xb728974c>
>>> list(a)
[]
>>> a = map(int, input().split())
3 4 5 0 -2
>>> list(a)
[3, 4, 5, 0, -2]
>>> list(a)
[]
>>>
Python3 map函数解析

本文介绍了Python3中map函数的行为特点。与Python2不同的是,Python3中的map函数返回一个可迭代的map对象而非直接的list。通过示例演示了如何将map对象转换为list并进行多次迭代的问题。
3071

被折叠的 条评论
为什么被折叠?



