python map 的用法


                                    map的用法

——、我們來分析map在python的源碼

 

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

  getattribute(字面意思是:獲取屬性)
  在python中的用法,
  

     __getattribute__是訪問屬性的方法,我們可以通過方法重寫來擴展方法的功能。

     對於python來說,屬性或者函數都可以被理解成一個屬性,且可以通過__getattribute__獲取。

   當獲取屬性時,直接return object.__getattribute__(self, *args, **kwargs)

   如果需要獲取某個方法的返回值時,則需要在函數后面加上一個()即可。如果不加的話,返回的是函數引用地址。見下方代碼



def __init__(self, func, *iterables): # real signature unknown; restored from __doc__
pass
這里是初始 map的函數要傳入的值,兩個值一個是函數,一個是可迭代的對象

def __iter__(self, *args, **kwargs): # real signature unknown
""" Implement iter(self). """
pass
  把可迭代的對象變成迭代器的對象

@staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object. See help(type) for accurate signature. """
pass


def __next__(self, *args, **kwargs): # real signature unknown
""" Implement next(self). """
pass

def __reduce__(self, *args, **kwargs): # real signature unknown
""" Return state information for pickling. """
pass

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM