map()内置函数

    首先,我们来看下map()内置函数的用法:

>>> help(map)
Help on class map in module builtins:

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.
  | 
  |  Methods defined here:
  | 
  |  __getattribute__(self, name, /)
  |      Return getattr(self, name).
  | 
  |  __iter__(self, /)
  |      Implement iter(self).
  | 
  |  __next__(self, /)
  |      Implement next(self).
  | 
  |  __reduce__(...)
  |      Return state information for pickling.
  | 
  |  ----------------------------------------------------------------------
  |  Static methods defined here:
  | 
  |  __new__(*args, **kwargs) from builtins.type
  |      Create and return a new object.  See help(type) for accurate signature.


  map()内置函数有两个参数,第一个参数为函数,第二个参数为可迭代对象,将可迭代对象中的每个元素作为函数的

参数进行运算,可以看到,第二个参数亦是一个收集参数,所以当第二个元素为收集参数时,其支持多个可迭代对象,

可迭代对象会依次取一个元素组成一个元组,然后传递给函数进行运算,当可迭代对象长度不一致时,到最短的那个

终止

例:

>>> list(map(lambda x:x**2,range(10)))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]


>>> list(map(lambda x,y:x+y,[1,8,10],[8,6,3,7,5,4]))
[9, 14, 13]