Python: 3.X版本map()的返回值问题

>>> def square(x):
    return x ** 2

>>> map(square, [1,2,3,4,5])
<map object at 0x7f9de4ae3208>

在python2中,map()会返回一个列表,但是在python3中返回iterators

如果需要当作列表使用,必须在map()外加上list(),转换成列表。

猜你喜欢

转载自blog.csdn.net/lcqin111/article/details/82659642