区别说明
Python2中map结果返回的是List,一个列表,例如下图:
Python3中map结果返回是一个对象,例如下图:
Python3中map源码如下:
可以看出里面是有一个迭代器的,我们使用的时候需要用迭代器返回每个结果,或者直接list(map)强制转化为python2中实现的效果。
class map(object):
"""
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.
"""
def __getattribute__(self, *args, **kwargs): # real signature unknown
""" Return getattr(self, name). """
pass
def __init__(self, func, *iterables): # real signature unknown; restored from __doc__
pass
def __iter__(self, *args, **kwargs): # real signature unknown
""" Implement iter(self). """
pass