Python基本數據類型(一)

1、int的函數說明(部分函數Python2特有,Python3已刪除,部分函數Python3新增;) html

class int(object):
    """
    int(x=0) -> int or long
    int(x=0) -> integer (Python3)
    
    Python2和Python3的用法一致,在Python2中,主要將數字或字符串轉換爲整數,若是沒有給出參數,則返回0;若是x是浮點數,則先截斷小數點在進行轉換;若是x在整數範圍以外,函數將返回long;在Python3中,主要將一個數字或字符串轉換爲整數,若是沒有參數,返回0;若是x是一個數,返回X __int__();若是x是浮點數,則先截斷小數點在進行轉換;
    例如(python2):
    >>> int()
    >>> int(1.9)
    >>> int(2**63)
    9223372036854775808L
    >>> int(x = 0)
    >>> int(x = 1.9)
    >>> int(x = 2**63)
    9223372036854775808L
    
    例如(python3):
    >>> int()
    >>> int(1.9)
    >>> int(2**63)
    >>> int(x = 0)
    >>> int(x = 1.9)
    >>> int(x = 2**63)
    int(x, base=10) -> int or long
    int(x, base=10) -> integer
    
    Python2和Python3的用法一致,主要將浮點數或數字字符串轉換爲整數,若是參數x不是一個數字,必須是字符串、數組bytes或bytearray類型,能夠在x能夠在前面加上「+」或「-」來表示正數及負數;base參數必須是整數,表示字符串參數的進制,有效值爲0和2-36,默認10就是表示使用十進制;當它是2時,表示二進制的字符串轉換。當它是8時,表示是八進制的字符串轉換。當它是16時,表示是十六進制的字符串轉換。當它是0時,它表示不是0進制,而是按照十進制進行轉換;
    例如:
    >>> int('100',base = 2)
    >>> int('100',base = 0)
    >>> int('100',base = 8)
    >>> int('100',base = 10)
    >>> int('a',base = 10)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'a'
    不是數字字符串會產生報錯;
    >>> int('-100',base = 8)
    -64
    >>> int('+100',base = 8)
    """
    def bit_length(self): # real signature unknown; restored from __doc__
        """
        int.bit_length() -> int
        
        返回表示該數字的時佔用的最少位數;
        例如:
        >>> int(10)
        >>> (10).bit_length()
        >>> bin(10)
        '0b1010'
        """
        return 0
    def conjugate(self, *args, **kwargs): # real signature unknown
        """ 返回該複數的共軛複數; """
        pass
    def from_bytes(cls, bytes, byteorder, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
        """
        int.from_bytes(bytes, byteorder, *, signed=False) -> int (Python3新增)
        
        返回給定的字節數組所表示的整數;
        bytes參數必須是一個相似字節的對象(例如字節或bytearray);
        byteorder參數肯定用於表示整數的字節順序。若是字節序是'big',最高有效字節排在在字節數組最開始。若是字節序是'little',則最高有效字節排在字節數組的結尾。若是要要求按照主機系統的本地字節順序排序,則需使用'sys.byteorder'做爲字節順序值;
        signed參數指示是否使用二進制補碼錶示整數;
        例如:
        >>> int.from_bytes(b'\x00\x10', byteorder='big')
        >>> int.from_bytes(b'\x00\x10', byteorder='little')
        >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=True)
        -1024
        >>> int.from_bytes(b'\xfc\x00', byteorder='big', signed=False)
        >>> int.from_bytes([255, 0, 0], byteorder='big')
        """
        pass
    def to_bytes(self, length, byteorder, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
        """
        int.to_bytes(length, byteorder, *, signed=False) -> bytes (Python3新增)
        
        返回一個表示整數的字節數組;        
        用字節長度表示整數。若是整數不能用給定的字節數表示,則會引起OverflowError;        
        byteorder參數肯定用於表示整數的字節順序。若是字節序是'big',最高有效字節排在在字節數組最開始。若是字節序是'little',則最高有效字節排在字節數組的結尾。若是要要求按照主機系統的本地字節順序排序,則需使用'sys.byteorder'做爲字節順序值;
        signed參數肯定是否使用二進制補碼錶示整數。若是signed是False,並給出一個負整數,則會引起一個OverflowError。 signed的默認值爲False;
        例如:
        >>> (1024).to_bytes(2, byteorder='big')
        b'\x04\x00'
        >>> (1024).to_bytes(10, byteorder='big')
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00'
        >>> (-1024).to_bytes(10, byteorder='big', signed=True)
        b'\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00'
        >>> x = 1000
        >>> x.to_bytes((x.bit_length() + 7) // 8, byteorder='little')
        b'\xe8\x03
        >>> (-1024).to_bytes(10, byteorder='big')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        OverflowError: can't convert negative int to unsigned
        """
        pass
    def __abs__(self): # real signature unknown; restored from __doc__
        """ 
        x.__abs__() 等同於 abs(x) 
        
        返回絕對值,參數能夠是:負數、正數、浮點數或者長整形;
        例如:
        >>> x = -2
        >>> x.__abs__()
        >>> abs(x)
        """
        pass
    def __add__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__add__(y) 等同於 x+y 

        加法;
        例如:
        >>> x = 2
        >>> y = 4
        >>> x.__add__(y)
        >>> x + y
               
        """
        pass
    def __and__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__and__(y) 等同於 x&y 

        按位與;
        例如:
        >>> x = 60
        >>> y = 13
        >>> bin(x)
        '0b111100'
        >>> bin(y)
        '0b1101'
        >>> x.__and__(y)
        >>> x & y
        """
        pass
    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__cmp__(y) <==> cmp(x,y) (Python2特有,Python3已刪除) 

        比較兩個對象x和y,若是x < y ,返回負數;x == y, 返回0;x > y,返回正數;
        例如:
        >>> x = 10
        >>> y = 20
        >>> x.__cmp__(y)
        -1
        >>> y.__cmp__(x)
        >>> cmp(x,y)
        -1
        >>> cmp(y,x)
        >>> y = 10
        >>> x.__cmp__(y)
        >>> cmp(x,y)
        """
        pass
    def __coerce__(self, y): # real signature unknown; restored from __doc__
        """
        x.__coerce__(y) <==> coerce(x, y) (Python2特有,Python3已刪除) 

        強制生成一個元組;
        例如:
        >>> x = 10
        >>> y = 20
        >>> x.__coerce__(y)
        (10, 20)
        >>> coerce(x,y)
        (10, 20)
        """
        pass
    def __bool__(self, *args, **kwargs): # real signature unknown
        """
        self != 0 (Python3新增)  

        布爾型判斷;
        例如:
        >>> a = True
        >>> b = False
        >>> a.__bool__()
        True
        >>> b.__bool__()
        False
        >>> x = 0
        >>> b = x > 1
        >>> b.__bool__()
        False    
        """
        pass
    def __ceil__(self, *args, **kwargs): # real signature unknown
        """ 
        返回數字的上入整數,若是數值是小數,則返回的數值是整數加一,配合math函數使用; (Python3新增)
        例如:
        >>> import math
        >>> math.ceil(4.1)

        """
    def __divmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__divmod__(y) 等同於 divmod(x, y)

        數字相除,將商和餘數返回一個數組,至關於 x//y ,返回(商,餘數)
        例如:
        >>> x = 10
        >>> y = 11
        >>> x.__divmod__(y)
        (0, 10)
        >>> divmod(x,y)
        (0, 10)
        """
        pass
    def __div__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__div__(y) 等同於 x/y (Python2特有,Python3已刪除)
 
        數字相除,返回商;
        例如:
        >>> x = 10
        >>> y = 9
        >>> x.__div__(y)
        >>> div(x,y)
        >>> x / y
        """
        pass
    def __eq__(self, *args, **kwargs): # real signature unknown
        """ 
        Return self==value. (Python3新增)   

        用於判斷數值是否相等,返回布爾值,等價於 x == y;
        例如:
        >>> x = 10
        >>> y = 11
        >>> x.__eq__(y)
        False
        >>> z = 10
        >>> x.__eq__(z)
        True
        """
        pass
    def __float__(self): # real signature unknown; restored from __doc__
        """ 
        x.__float__() <==> float(x) 

        轉換爲浮點類型,即小數型;
        例如:
        >>> x = 1.4
        >>> x.__float__()
        1.4
        >>> float(x)
        1.4
        >>> y = 2
        >>> y.__float__()
        2.0
        >>> float(y)
        2.0
        """
        pass
    def __floordiv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__floordiv__(y) 等同於 x//y 

        用於數字相除取其商,例如, 4//3 返回 1;
        例如:
        >>> x = 9
        >>> y = 7
        >>> x.__floordiv__(y)
        >>> x // y
        """
        pass
    def __floor__(self, *args, **kwargs): # real signature unknown
        """ 
        Flooring an Integral returns itself. (Python3新增)
  
        返回數字的下舍整數,配合math函數使用;
        例如:
        >>> import math
        >>> x = 1.54
        >>> math.floor(x)
        """
        pass
    def __format__(self, *args, **kwargs): # real signature unknown
        """
        無心義;
        """
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ 
        x.__getattribute__('name') 等同於 x.name 
        """
        pass
    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        """
        內部調用 __new__方法或建立對象時傳入參數使用;
        """
        pass
    def __ge__(self, *args, **kwargs): # real signature unknown
        """ 
        Return self>=value. (Python3新增)   

        數字判斷大於等於,至關於 x >= y,返回布爾值;
        例如:
        >>> x = 4
        >>> y = 4
        >>> x.__ge__(y)
        True
        >>> x >= y
        True
        >>> x = 5
        >>> x.__ge__(y)
        True
        >>> x >= y
        True
        >>> y = 7
        >>> x.__ge__(y)
        False
        >>> x >= y
        False
        """
        pass
    def __gt__(self, *args, **kwargs): # real signature unknown
        """ 
        Return self>value. (Python3新增) 
  
        數字大於判斷,至關於 x > y,返回布爾值;
        例如:
        >>> x = 10
        >>> y = 9
        >>> x.__gt__(y)
        True
        >>> y.__gt__(x)
        False
        >>> x > y
        True
        >>> y < x
        False
        >>> x = 4
        >>> y = 4
        >>> x > y
        False
        >>> x.__gt__(y)
        False
        """
        pass
    def __hash__(self): # real signature unknown; restored from __doc__
        """ 
        x.__hash__() <==> hash(x) 

        若是對象object爲哈希表類型,返回對象object的哈希值。哈希值爲整數。在字典查找中,哈希值用於快速比較字典的鍵。兩個數值若是相等,則哈希值也相等;
        """
        pass
    def __hex__(self): # real signature unknown; restored from __doc__
        """ 
        x.__hex__() 等同於 hex(x) 

        返回當前數的十六進制表示; (Python2特有,Python3已刪除)
        例如:
        >>> x = 100
        >>> x.__hex__()
        '0x64'
        >>> hex(x)
        '0x64'
        """
        pass
    def __index__(self): # real signature unknown; restored from __doc__
        """ 
        x[y:z] <==> x[y.__index__():z.__index__()] 

        用於切片,數字無心義;
        """
        pass
    def __init__(self, x, base=10): # known special case of int.__init__
        """
        構造方法,執行 x = 123 或 x = int(10) 時,自動調用;
        """
        pass
    def __int__(self): # real signature unknown; restored from __doc__
        """ 
        x.__int__() 等同於 int(x) 

        轉換爲整數;
        """
        pass
    def __invert__(self): # real signature unknown; restored from __doc__
        """ 
        x.__invert__() 等同於 ~x 

        數字取反操做;
        例如:
        >>> x = 10
        >>> x.__invert__()
        -11
        >>> ~x
        -11
        """
        pass
    def __long__(self): # real signature unknown; restored from __doc__
        """ 
        x.__long__() 等同於 long(x) 

        轉換爲長整數; (Python2特有,Python3已刪除)
        例如:
        >>> x = 10
        >>> x.__long__()
        10L
        >>> long(x)
        10L
        """
        pass
    def __le__(self, *args, **kwargs): # real signature unknown
        """ 
        Return self<=value. (Python3新增)  

        數字小於等於判斷,至關於 x <= y,返回布爾值;
        例如:
        >>> x = 2
        >>> y = 4
        >>> x.__le__(y)
        True
        >>> x <= y
        True
        >>> y.__le__(x)
        False
        >>> y <= x
        False
        >>> y = 2
        >>> x.__le__(y)
        True
        >>> x <= y
        True
        """
        pass
    def __lshift__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__lshift__(y) 等同於 x<<y 

        實現一個位左移操做的功能,即x向左移動y位;
        例如:
        >>> x = 2
        >>> y = 1
        >>> bin(x)
        '0b10'
        >>> x.__lshift__(y)
        >>> z = x.__lshift__(y)
        >>> bin(y)
        '0b100'
        >>> y = 2
        >>> z = x.__lshift__(y)
        >>> x.__lshift__(y)
        >>> bin(z)
        '0b1000'
        """
        pass
    def __lt__(self, *args, **kwargs): # real signature unknown
        """ 
        Return self<value. 

        數字小於判斷,至關於 x < y,返回布爾值; (Python3新增)
        例如:
        >>> x = 2
        >>> y = 4
        >>> x.__lt__(y)
        True
        >>> x < y
        True
        >>> y.__lt__(x)
        False
        >>> y < x
        False
        """
        pass
    def __mod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__mod__(y) 等同於 x%y 

        實現一個「%」操做符表明的取模操做;
        例如:
        >>> x = 7
        >>> y = 3
        >>> x.__mod__(y)
        >>> x % y
        """
        pass
    def __mul__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__mul__(y) 等同於 x*y
 
        實現乘法;
        例如:
        >>> x = 2
        >>> y = 4
        >>> x.__mul__(y)
        >>> x * y
        """
        pass
    def __neg__(self): # real signature unknown; restored from __doc__
        """ 
        x.__neg__() 等同於 -x 

        數字取負操做;
        例如:
        >>> x = 3
        >>> x.__neg__()
        -3
        >>> -x
        -3
        """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ 
        T.__new__(S, ...) -> a new object with type S, a subtype of T 
        __new__方法接受的參數雖然也是和__init__同樣,但__init__是在類實例建立以後調用,而__new__方法正是建立這個類實例的方法;__new__方法主要是當你繼承一些不可變的class時(好比int, str, tuple),提供給你一個自定義這些類的實例化過程的途徑;
        """
        pass
    def __ne__(self, *args, **kwargs): # real signature unknown
        """ 
        Return self!=value. 

        數字不相等判斷,至關於x != y,返回布爾值; (Python3新增)
        例如:
        >>> x = 2
        >>> y = 4
        >>> x.__ne__(y)
        True
        >>> x != y
        True
        >>> y =2
        >>> x.__ne__(y)
        False
        >>> x != y
        False
        """
        pass
    def __nonzero__(self): # real signature unknown; restored from __doc__
        """ 
        x.__nonzero__() 等同於 x != 0 

        數字不等於0判斷,至關於x != 0,返回布爾值; (Python2特有,Python3已刪除)
        例如:
        >>> x = 2
        >>> x.__nonzero__()
        True
        >>> x != 0
        True
        >>> x = 0
        >>> x.__nonzero__()
        False
        >>> x != 0
        False
        """
        pass
    def __oct__(self): # real signature unknown; restored from __doc__
        """ 
        x.__oct__() 等同於 oct(x) 

        返回當前數的八進制表示; (Python2特有,Python3已刪除)
        例如:
        >>> x = 17
        >>> x.__oct__()
        '021'
        >>> oct(x)
        '021'
        """
        pass
    def __or__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__or__(y) 等同於 x|y 

        按位或;
        例如:
        >>> x = 3
        >>> y = 5
        >>> bin(x)
        '0b11'
        >>> bin(y)
        '0b101'
        >>> x.__or__(y)
        >>> x|y
        >>> a = x.__or__(y)
        >>> bin(a)
        '0b111'
        """
        pass
    def __pos__(self): # real signature unknown; restored from __doc__
        """ 
        x.__pos__() 等同於 +x 

        數字取正操做;
        """
        pass
    def __pow__(self, y, z=None): # real signature unknown; restored from __doc__
        """ 
        x.__pow__(y[, z]) 等同於 pow(x, y[, z]) 

        冪,次方,計算x的y次方,若是z在存在,則再對結果進行取模,其結果等效於pow(x,y) %z,也能夠配合math函數使用;pow()經過內置的方法直接調用,內置方法會把參數做爲整型,而math模塊則會把參數轉換爲float;
        例如:
        >>> x = 2
        >>> y = 4
        >>> pow(x,y)
        >>> z = 3
        >>> pow(x,y,z)
        >>> import math
        >>> math.pow(x,y)
        16.0
        """
        pass
    def __radd__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__radd__(y) 等同於 y+x 

        右加法;
        例如:
        >>> x = 2
        >>> y = 1
        >>> x.__radd__(y)
        >>> y + x
        """
        pass
    def __rand__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rand__(y) 等同於 y&x 
        
        按位右與;
        例如:
        >>> x = 63
        >>> y = 13
        >>> bin(x)
        '0b111111'
        >>> bin(y)
        '0b1101'
        >>> x.__rand__(y)
        >>> y & x
        >>> a = x.__rand__(y)
        >>> bin(a)
        '0b1101'
        >>> a = x & y
        >>> bin(a)
        '0b1101'
        """
        pass
    def __rdivmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rdivmod__(y) 等同於 divmod(y, x) 

        數字相除,將商和餘數返回一個數組,至關於 y//x ,返回(商,餘數)
        """
        pass
    def __rdiv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rdiv__(y) 等同於 y/x 

        數字相除,返回商; (Python2特有,Python3已刪除)
        """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ 
        x.__repr__() 等同於 repr(x) 

        轉化爲解釋器可讀取的形式,即轉換爲字符串類型;
        例如:
        >>> x = 2.0
        >>> repr(x)
        '2.0'
        >>> a = repr(x)
        >>> type(a)
        <type 'str'>
        """
        pass
    def __rfloordiv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rfloordiv__(y) 等同於 y//x 

        用於數字相除取其商;
        """
        pass
    def __rlshift__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rlshift__(y) 等同於 y<<x 
        
        實現一個位左移操做的功能,即y向左移動x位;
        例如:
        >>> x = 1
        >>> y = 2
        >>> bin(y)
        '0b10'
        >>> x.__rlshift__(y)
        >>> z = x.__rlshift__(y)
        >>> bin(z)
        '0b100'
        >>> z = y << x
        >>> bin(z)
        '0b100'
        >>> x = 2
        >>> z = x.__rlshift__(y)
        >>> bin(z)
        '0b1000'
        """
        pass
    def __rmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rmod__(y) 等同於 y%x 

        實現一個右「%」操做符表明的取模操做;
        """
        pass
    def __rmul__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rmul__(y) 等同於 y*x 

        實現右乘法;
        """
        pass
    def __ror__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ror__(y) 等同於 y|x 

        按位右或;
        """
        pass
    def __round__(self, *args, **kwargs): # real signature unknown
        """
        x.__rount__() 等同於 round( x [, n]  )

        返回浮點數x的四捨五入值,n參數表示保留的小數點位數; (Python3新增)
        例如:
        >>> x = 2.56
        >>> x.__round__()
        >>> x.__round__(1)
        2.6
        >>> x.__round__(2)
        2.56
        >>> round(x)
        >>> round(x,1)
        2.6
        >>> round(x,2)
        2.56
        """
        pass
    def __rpow__(self, x, z=None): # real signature unknown; restored from __doc__
        """ 
        y.__rpow__(x[, z]) 等同於 pow(x, y[, z]) 

        冪,次方,計算x的y次方,若是z在存在,則再對結果進行取模,其結果等效於pow(x,y) %z,也能夠配合math函數使用;pow()經過內置的方法直接調用,內置方法會把參數做爲整型,而math模塊則會把參數轉換爲float;
        """
        pass
    def __rrshift__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rrshift__(y) 等同於 y>>x 

        實現一個位右移操做的功能,即y向右移動x位;
        例如:
        >>> x = 1
        >>> y = 4
        >>> bin(y)
        '0b100'
        >>> x.__rrshift__(y)
        >>> z = x.__rrshift__(y)
        >>> bin(z)
        '0b10'
        >>> y >> x
        >>> z = y >> x
        >>> bin(z)
        '0b10'
        """
        pass
    def __rshift__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rshift__(y) 等同於 x>>y

        實現一個位右移操做的功能,即x向右移動y位;
        例如:
        >>> x = 4
        >>> y = 1
        >>> bin(x)
        '0b100'
        >>> x.__rshift__(y)
        >>> z = x.__rrshift__(y)
        >>> bin(z)
        '0b10'
        >>> x >> y
        >>> z = x >> y
        >>> bin(z)
        '0b10'
        """
        pass
    def __rsub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rsub__(y) 等同於 y-x 

        右減法,至關於y減x;
        例如:
        >>> x = 4
        >>> y = 1
        >>> x.__rsub__(y)
        -3
        >>> y - x
        -3
        """
        pass
    def __rtruediv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rtruediv__(y) 等同於 y/x 

        右除法,至關於y除以x;
        """
        pass
    def __rxor__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rxor__(y) 等同於 y^x 

        按位右異或,至關於y按x進行異或;
        """
        pass
    def __sizeof__(self, *args, **kwargs): # real signature unknown
        """ 
        返回內存中的大小(以字節爲單位); (Python2存在於long函數,Python3中合併進int函數)
        """
    def __str__(self): # real signature unknown; restored from __doc__
        """ 
        x.__str__() 等同於 str(x) 

        轉換爲人閱讀的形式,若是沒有適於人閱讀的解釋形式的話,則返回解釋器課閱讀的形式,即轉換爲字符串類型;
        例如:
        >>> x = 1
        >>> x.__str__()
        '1'
        >>> a = x.__str__()
        >>> type(a)
        <type 'str'>
        >>> a = str(x)
        >>> type(a)
        <type 'str'>
        """
        pass
    def __sub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__sub__(y) <==> x-y 

        減法,至關於x減y;
        """
        pass
    def __truediv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__truediv__(y) <==> x/y 

        除法,至關於x除以y;
        """
        pass
    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ 
        返回數值被截取爲整形的值,在整形中無心義;
        """
        pass
    def __xor__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__xor__(y) 等同於 x^y 

        按位異或,至關於x按y進行異或;
        """
        pass
    denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """
    分母,等於1;
    """
    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """
    虛數,無心義;
    """
    numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """
    分子,等於數字大小;
    """
    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """
    實數,無心義;
    """
int

2、long的函數說明(函數與方法與int一致,Python3已與int類型進行合併;)node

class long(object):
    """
    long(x=0) -> long
    long(x, base=10) -> long
    
    Convert a number or string to a long integer, or return 0L if no arguments
    are given.  If x is floating point, the conversion truncates towards zero.
    
    If x is not a number or if base is given, then x must be a string or
    Unicode object representing an integer literal in the given base.  The
    literal can be preceded by '+' or '-' and be surrounded by whitespace.
    The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
    interpret the base from the string as an integer literal.
    >>> int('0b100', base=0)
    4L
    """
    def bit_length(self): # real signature unknown; restored from __doc__
        """
        long.bit_length() -> int or long
        
        Number of bits necessary to represent self in binary.
        >>> bin(37L)
        '0b100101'
        >>> (37L).bit_length()
        6
        """
        return 0
    def conjugate(self, *args, **kwargs): # real signature unknown
        """ Returns self, the complex conjugate of any long. """
        pass
    def __abs__(self): # real signature unknown; restored from __doc__
        """ x.__abs__() <==> abs(x) """
        pass
    def __add__(self, y): # real signature unknown; restored from __doc__
        """ x.__add__(y) <==> x+y """
        pass
    def __and__(self, y): # real signature unknown; restored from __doc__
        """ x.__and__(y) <==> x&y """
        pass
    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ x.__cmp__(y) <==> cmp(x,y) """
        pass
    def __coerce__(self, y): # real signature unknown; restored from __doc__
        """ x.__coerce__(y) <==> coerce(x, y) """
        pass
    def __divmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__divmod__(y) <==> divmod(x, y) """
        pass
    def __div__(self, y): # real signature unknown; restored from __doc__
        """ x.__div__(y) <==> x/y """
        pass
    def __float__(self): # real signature unknown; restored from __doc__
        """ x.__float__() <==> float(x) """
        pass
    def __floordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__floordiv__(y) <==> x//y """
        pass
    def __format__(self, *args, **kwargs): # real signature unknown
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass
    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass
    def __hash__(self): # real signature unknown; restored from __doc__
        """ x.__hash__() <==> hash(x) """
        pass
    def __hex__(self): # real signature unknown; restored from __doc__
        """ x.__hex__() <==> hex(x) """
        pass
    def __index__(self): # real signature unknown; restored from __doc__
        """ x[y:z] <==> x[y.__index__():z.__index__()] """
        pass
    def __init__(self, x=0): # real signature unknown; restored from __doc__
        pass
    def __int__(self): # real signature unknown; restored from __doc__
        """ x.__int__() <==> int(x) """
        pass
    def __invert__(self): # real signature unknown; restored from __doc__
        """ x.__invert__() <==> ~x """
        pass
    def __long__(self): # real signature unknown; restored from __doc__
        """ x.__long__() <==> long(x) """
        pass
    def __lshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__lshift__(y) <==> x<<y """
        pass
    def __mod__(self, y): # real signature unknown; restored from __doc__
        """ x.__mod__(y) <==> x%y """
        pass
    def __mul__(self, y): # real signature unknown; restored from __doc__
        """ x.__mul__(y) <==> x*y """
        pass
    def __neg__(self): # real signature unknown; restored from __doc__
        """ x.__neg__() <==> -x """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass
    def __nonzero__(self): # real signature unknown; restored from __doc__
        """ x.__nonzero__() <==> x != 0 """
        pass
    def __oct__(self): # real signature unknown; restored from __doc__
        """ x.__oct__() <==> oct(x) """
        pass
    def __or__(self, y): # real signature unknown; restored from __doc__
        """ x.__or__(y) <==> x|y """
        pass
    def __pos__(self): # real signature unknown; restored from __doc__
        """ x.__pos__() <==> +x """
        pass
    def __pow__(self, y, z=None): # real signature unknown; restored from __doc__
        """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
        pass
    def __radd__(self, y): # real signature unknown; restored from __doc__
        """ x.__radd__(y) <==> y+x """
        pass
    def __rand__(self, y): # real signature unknown; restored from __doc__
        """ x.__rand__(y) <==> y&x """
        pass
    def __rdivmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__rdivmod__(y) <==> divmod(y, x) """
        pass
    def __rdiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rdiv__(y) <==> y/x """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass
    def __rfloordiv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rfloordiv__(y) <==> y//x """
        pass
    def __rlshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rlshift__(y) <==> y<<x """
        pass
    def __rmod__(self, y): # real signature unknown; restored from __doc__
        """ x.__rmod__(y) <==> y%x """
        pass
    def __rmul__(self, y): # real signature unknown; restored from __doc__
        """ x.__rmul__(y) <==> y*x """
        pass
    def __ror__(self, y): # real signature unknown; restored from __doc__
        """ x.__ror__(y) <==> y|x """
        pass
    def __rpow__(self, x, z=None): # real signature unknown; restored from __doc__
        """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
        pass
    def __rrshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rrshift__(y) <==> y>>x """
        pass
    def __rshift__(self, y): # real signature unknown; restored from __doc__
        """ x.__rshift__(y) <==> x>>y """
        pass
    def __rsub__(self, y): # real signature unknown; restored from __doc__
        """ x.__rsub__(y) <==> y-x """
        pass
    def __rtruediv__(self, y): # real signature unknown; restored from __doc__
        """ x.__rtruediv__(y) <==> y/x """
        pass
    def __rxor__(self, y): # real signature unknown; restored from __doc__
        """ x.__rxor__(y) <==> y^x """
        pass
    def __sizeof__(self, *args, **kwargs): # real signature unknown
        """ Returns size in memory, in bytes """
        pass
    def __str__(self): # real signature unknown; restored from __doc__
        """ x.__str__() <==> str(x) """
        pass
    def __sub__(self, y): # real signature unknown; restored from __doc__
        """ x.__sub__(y) <==> x-y """
        pass
    def __truediv__(self, y): # real signature unknown; restored from __doc__
        """ x.__truediv__(y) <==> x/y """
        pass
    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ Truncating an Integral returns itself. """
        pass
    def __xor__(self, y): # real signature unknown; restored from __doc__
        """ x.__xor__(y) <==> x^y """
        pass
    denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the denominator of a rational number in lowest terms"""
    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the imaginary part of a complex number"""
    numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the numerator of a rational number in lowest terms"""
    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the real part of a complex number"""
long

3、float的函數說明(函數與方法的使用與int相似;)  python

class float(object):
    """
    float(x) -> 

    將字符串或數字轉換爲浮點數;
    """
    def as_integer_ratio(self): # real signature unknown; restored from __doc__
        """
        float.as_integer_ratio() -> (int, int)
       
        獲取值的最簡化結果,返回一對整數,其比例徹底等於原始浮點數,並使用正分母;在無窮大上產生OverflowError,在NaNs上產生ValueError;
        例如:        
        >>> (10.0).as_integer_ratio()
        (10, 1)
        >>> (0.0).as_integer_ratio()
        (0, 1)
        >>> (-.25).as_integer_ratio()
        (-1, 4)
        """
        pass
    def conjugate(self, *args, **kwargs): # real signature unknown
        """ 
        返回該複數的共軛複數;
        """
        pass
    def fromhex(self, string): # real signature unknown; restored from __doc__
        """
        float.fromhex(string) -> float
        
        將十六進制轉換爲浮點數;
        例如:
        >>> float.fromhex('0x1.ffffp10')
        2047.984375
        >>> float.fromhex('-0x1p-1074')
        -4.9406564584124654e-324
        """
        return 0.0
    def hex(self): # real signature unknown; restored from __doc__
        """
        float.hex() -> string
        
        將浮點數轉換爲十六進制;
        例如:
        >>> (-0.1).hex()
        '-0x1.999999999999ap-4'
        >>> 3.14159.hex()
        '0x1.921f9f01b866ep+1'
        """
        return ""
    def is_integer(self, *args, **kwargs): # real signature unknown
        """ 
        判斷是否是整數,返回布爾值;
        例如:
        >>> x = 1.1
        >>> x.is_integer()
        False
        >>> x = 2.0
        >>> x.is_integer()
        True
        """
        pass
    def __abs__(self): # real signature unknown; restored from __doc__
        """ 
        x.__abs__() 等同於 abs(x) 

        返回絕對值,參數能夠是:負數、正數、浮點數或者長整形;
        例如:
        >>> x = -1.1
        >>> x.__abs__()
        1.1
        >>> abs(x)
        1.1
        """
        pass
    def __add__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__add__(y) 等同於 x+y 
        """
        pass
    def __coerce__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__coerce__(y) 等同於 coerce(x, y) 

        強制生成一個元組; (Python2特有,Python3已刪除) 
        例如:
        >>> x = 1.1
        >>> y = 2.2
        >>> x.__coerce__(y)
        (1.1, 2.2)
        >>> coerce(x,y)
        (1.1, 2.2)
        """
        pass
    def __bool__(self, *args, **kwargs): # real signature unknown
        """ 
        self != 0 (Python3新增) 

        布爾型判斷;
        """
        pass
    def __divmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__divmod__(y) 等同於 divmod(x, y) 

        數字相除,將商和餘數返回一個數組,至關於 x//y ,返回(商,餘數);
        例如:
        >>> x = 1.1
        >>> y = 3.3
        >>> x.__divmod__(y)
        (0.0, 1.1)
        >>> divmod(x,y)
        (0.0, 1.1)
        """
        pass
    def __div__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__div__(y) 等同於 x/y(Python2特有,Python3已刪除) 

        數字相除,返回商;
        """
        pass
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__eq__(y) 等同於 x==y 

        用於判斷數值是否相等,返回布爾值,等價於 x == y;
        """
        pass
    def __float__(self): # real signature unknown; restored from __doc__
        """ 
        x.__float__() 等同於 float(x) 

        轉換爲浮點類型,即小數型;
        例如:
        >>> x = 2
        >>> x.__float__()
        2.0
        >>> float(x)
        2.0
        """
        pass
    def __floordiv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__floordiv__(y) 等同於 x//y 

        用於數字相除取其商;
        """
        pass
    def __format__(self, format_spec): # real signature unknown; restored from __doc__
        """
        float.__format__(format_spec) -> string
        
        無心義;
        """
        return ""
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ 
        x.__getattribute__('name') 等同於 x.name 
        """
        pass
    def __getformat__(self, typestr): # real signature unknown; restored from __doc__
        """
        float.__getformat__(typestr) -> string

        你最好不要使用這個函數,它的主要存在Python中的的測試套件中;
        typestr參數必須是'double'和'float'類型;    
        This function returns whichever of
        'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the
        format of floating point numbers used by the C type named by typestr.
        """
        return ""
    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        """
        內部調用 __new__方法或建立對象時傳入參數使用;
        """
        pass
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ge__(y) 等同於 x>=y 

        數字判斷大於等於,至關於 x >= y,返回布爾值;
        """
        pass
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__gt__(y) 等同於 x>y 

        數字大於判斷,至關於 x > y,返回布爾值;
        """
        pass
    def __hash__(self): # real signature unknown; restored from __doc__
        """ 
        x.__hash__() 等同於 hash(x) 

        若是對象object爲哈希表類型,返回對象object的哈希值。哈希值爲整數。在字典查找中,哈希值用於快速比較字典的鍵。兩個數值若是相等,則哈希值也相等;
        """
        pass
    def __init__(self, x): # real signature unknown; restored from __doc__
        """
        構造方法,執行 x = 1.1 或 x = float(1.1) 時,自動調用;
        """
        pass
    def __int__(self): # real signature unknown; restored from __doc__
        """ 
        x.__int__() 等同於 int(x) 

        轉換爲整數;
        """
        pass
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__le__(y) 等同於 x<=y 

        數字小於等於判斷,至關於 x <= y,返回布爾值;
        """
        pass
    def __long__(self): # real signature unknown; restored from __doc__
        """ 
        x.__long__() 等同於 long(x) 

        轉換爲長整數; (Python2特有,Python3已刪除)
        """
        pass
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__lt__(y) 等同於 x<y 

        數字小於判斷,至關於 x < y,返回布爾值;
        """
        pass
    def __mod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__mod__(y) 等同於 x%y 

        實現一個「%」操做符表明的取模操做;
        """
        pass
    def __mul__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__mul__(y) 等同於 x*y 

        實現乘法;
        """
        pass
    def __neg__(self): # real signature unknown; restored from __doc__
        """ 
        x.__neg__() 等同於 -x 

        數字取負操做;
        """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ 
        T.__new__(S, ...) -> a new object with type S, a subtype of T 
        __new__方法接受的參數雖然也是和__init__同樣,但__init__是在類實例建立以後調用,而__new__方法正是建立這個類實例的方法;__new__方法主要是當你繼承一些不可變的class時(好比int, str, tuple),提供給你一個自定義這些類的實例化過程的途徑;
        """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ne__(y) 等同於 x!=y 

        數字不相等判斷,至關於x != y,返回布爾值;
        """
        pass
    def __nonzero__(self): # real signature unknown; restored from __doc__
        """ 
        x.__nonzero__() 等同於 x != 0 

        數字不等於0判斷,至關於x != 0,返回布爾值; (Python2特有,Python3已刪除)
        """
        pass
    def __pos__(self): # real signature unknown; restored from __doc__
        """ 
        x.__pos__() 等同於 +x 

        數字取正操做;
        """
        pass
    def __pow__(self, y, z=None): # real signature unknown; restored from __doc__
        """ 
        x.__pow__(y[, z]) 等同於 pow(x, y[, z]) 

        冪,次方,計算x的y次方,若是z在存在,則再對結果進行取模,其結果等效於pow(x,y) %z,也能夠配合math函數使用;
        """
        pass
    def __radd__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__radd__(y) 等同於 y+x 

        右加法;
        """
        pass
    def __rdivmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rdivmod__(y) 等同於 divmod(y, x) 

        數字相除,將商和餘數返回一個數組,至關於 y//x ,返回(商,餘數)
        """
        pass
    def __rdiv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rdiv__(y) 等同於 y/x 

        數字相除,返回商; (Python2特有,Python3已刪除)
        """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ 
        x.__repr__() 等同於 repr(x) 

        轉化爲解釋器可讀取的形式,即轉換爲字符串類型;
        """
        pass
    def __rfloordiv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rfloordiv__(y) 等同於 y//x 

        用於數字相除取其商;
        """
        pass
    def __rmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rmod__(y) 等同於 y%x 

        實現一個右「%」操做符表明的取模操做;
        """
        pass
    def __rmul__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rmul__(y) 等同於 y*x 

        實現右乘法;
        """
        pass
    def __rpow__(self, x, z=None): # real signature unknown; restored from __doc__
        """ 
        y.__rpow__(x[, z]) 等同於 pow(x, y[, z]) 

        冪,次方,計算x的y次方,若是z在存在,則再對結果進行取模,其結果等效於pow(x,y) %z,也能夠配合math函數使用;
        """
        pass
    def __rsub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rsub__(y) 等同於 y-x 

        右減法,至關於y減x;
        """
        pass
    def __rtruediv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rtruediv__(y) 等同於 y/x 

        右除法,至關於y除以x;
        """
        pass
    def __setformat__(self, typestr, fmt): # real signature unknown; restored from __doc__
        """
        float.__setformat__(typestr, fmt) -> None
        
        你最好不要使用這個函數,它的主要存在Python中的的測試套件中;
        
        typestr must be 'double' or 'float'.  fmt must be one of 'unknown',
        'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be
        one of the latter two if it appears to match the underlying C reality.
        
        Override the automatic determination of C-level floating point type.
        This affects how floats are converted to and from binary strings.
        """
        pass
    def __str__(self): # real signature unknown; restored from __doc__
        """ 
        x.__str__() 等同於 str(x) 

        轉換爲人閱讀的形式,若是沒有適於人閱讀的解釋形式的話,則返回解釋器課閱讀的形式,即轉換爲字符串類型;
        """
        pass
    def __sub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__sub__(y) 等同於 x-y 

        減法,至關於x減y;
        """
        pass
    def __truediv__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__truediv__(y) 等同於 x/y 

        除法,至關於x除以y;
        """
        pass
    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ 
        返回0和x之間最接近x的積分,即返回數值被截取爲整形的值;
        例如:
        >>> x = 1.1
        >>> x.__trunc__()
        >>> x = 3.6
        >>> x.__trunc__()
        """
        pass
    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """
    虛數,無心義;
    """
    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """
    實數,無心義;
    """
float

4、str的函數說明git

字符串是Python中最經常使用的數據類型,可使用引號('或")來建立字符串,同時支撐反斜槓(\)轉義特殊字符,Python不支持單字符類型,單字符也在Python也是做爲一個字符串使用;編程

在python中字符串提供的函數以下:api

class str(basestring):
    """
    str(object='') -> string
     
    Python2和Python3的用法一致,在Python2中,主要將參數以字符串形式進行返回,若是參數是字符串,則直接返回;
    在Python3中,主要爲給定對象建立一個新的字符串對象,若是指定了錯誤的編碼,則必須爲對象指定數據緩衝區來處理錯誤編碼;不然,返回the result of object.__str__() (if defined) or repr(object)的報錯; 默認的encoding爲sys.getdefaultencoding();默認的錯誤類型爲"strict";
    """
    def capitalize(self): # real signature unknown; restored from __doc__
        """
        S.capitalize() -> string
         
        首字母變大寫;
        例如:
        >>> x = 'abc'
        >>> x.capitalize()
        'Abc'
        """
        return ""
    def casefold(self): # real signature unknown; restored from __doc__
        """
        S.casefold() -> str
        
        把字符串變成小寫,用於不區分大小寫的字符串比較,與lower()的區別,在漢語、英語環境下面,繼續用lower()沒問題;要處理其它語言且存在大小寫狀況的時候需用casefold(); (Python3新增)
        例如:
        >>> name = 'Test User'
        >>> name.casefold()
        'test user'
        """
        return ""
    def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
        """
        S.center(width[, fillchar]) -> string
         
        內容居中,width:總長度;fillchar:空白處填充內容,默認無;
        例如:
        >>> x = 'abc'
        >>> x.center(50,'*')
        '***********************abc************************'
        """
        return ""
    def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.count(sub[, start[, end]]) -> int
         
        用於統計字符串裏某個字符出現的次數,可選參數爲在字符串搜索的開始與結束位置,即sub參數表示搜索的子字符串;start參數表示字符串開始搜索的位置,默認爲第一個字符,第一個字符索引值爲0;end參數表示字符串中結束搜索的位置,字符中第一個字符的索引爲 0,默認爲字符串的最後一個位置;
        例如:
        >>> x = 'caaaaaaaab'
        >>> x.count('a')
        8
        >>> x.count('a',1,7)
        6
        """
        return 0
    def decode(self, encoding=None, errors=None): # real signature unknown; restored from __doc__
        """
        S.decode([encoding[,errors]]) -> object
         
        以encoding指定的編碼格式解碼字符串,默認編碼爲字符串編碼;即encoding參數指要使用的編碼,如"UTF-8";errors參數指設置不一樣錯誤的處理方案,默認爲 'strict',意爲編碼錯誤引發一個UnicodeError,其餘值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及經過 codecs.register_error() 註冊的任何值; (Python2特有,Python3已刪除)
        例如:
        >>> str = 'this is string example!'
        >>> str = str.encode('base64','strict')
        >>> print 'Encoded String: ' + str
        Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZSE=
        >>> print 'Decoded String: ' + str.decode('base64','strict')
        Decoded String: this is string example!
        """
        return object()
    def encode(self, encoding=None, errors=None): # real signature unknown; restored from __doc__
        """
        S.encode([encoding[,errors]]) -> object
         
        以encoding指定的編碼格式編碼字符串,errors參數能夠指定不一樣的錯誤處理方案;即encoding參數指要使用的編碼,如"UTF-8";errors參數指設置不一樣錯誤的處理方案,默認爲 'strict',意爲編碼錯誤引發一個UnicodeError,其餘值有 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 以及經過codecs.register_error()註冊的任何值;
        例如:
        >>> str = 'this is string example!'
        >>> print 'Encoded String: ' + str.encode('base64','strict')
        Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZSE=
        """
        return object()
    def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.endswith(suffix[, start[, end]]) -> bool
         
        用於判斷字符串是否以指定後綴結尾,若是以指定後綴結尾返回True,不然返回False,可選參數"start"與"end"爲檢索字符串的開始與結束位置;即suffix參數指該參數能夠是一個字符串或者是一個元素,start參數指字符串中的開始位置,end參數指字符中結束位置;
        例如:
        >>> str = 'this is string example!'
        >>> print str.endswith('e')
        False
        >>> print str.endswith('e!')
        True
        >>> print str.endswith('e!',3)
        True
        >>> print str.endswith('e!',3,8)
        False
        """
        return False
    def expandtabs(self, tabsize=None): # real signature unknown; restored from __doc__
        """
        S.expandtabs([tabsize]) -> string
         
        把字符串中的tab符號('\t')轉爲空格,tab符號('\t')默認的空格數是8,其中tabsize參數指定轉換字符串中的tab符號('\t')轉爲空格的字符數;
        例如:
        >>> str = 'this is\tstring example!'
        >>> print 'Original string: ' + str
        Original string: this is        string example!
        >>> print 'Defualt exapanded tab: ' +  str.expandtabs()
        Defualt exapanded tab: this is string example!
        >>> print 'Double exapanded tab: ' +  str.expandtabs(16)
        Double exapanded tab: this is         string example!
        """
        return ""
    def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.find(sub [,start [,end]]) -> int
         
        檢測字符串中是否包含子字符串str,若是指定beg(開始)和end(結束)範圍,則檢查是否包含在指定範圍內,若是包含子字符串返回開始的索引值,不然返回-1;即str參數指定檢索的字符串;beg參數指開始索引,默認爲0;end參數指結束索引,默認爲字符串的長度;
        例如:
        >>> str = 'this is string example!'
        >>> str.find('ex')
        15
        >>> str.find('ex',10)
        15
        >>> str.find('ex',40)
        -1
        """
        return 0
    def format(self, *args, **kwargs): # known special case of str.format
        """
        S.format(*args, **kwargs) -> string
         
        執行字符串格式化操做,替換字段使用{}分隔,替換字段能夠是表示位置的位置或keyword參數名字;其中args指要替換的參數1,kwargs指要替換的參數2;
        例如:
        >>> '{0}, {1}, {2}'.format('a', 'b', 'c')
        'a, b, c'
        >>> '{}, {}, {}'.format('a', 'b', 'c')
        'a, b, c'
        >>> '{2}, {1}, {0}'.format('a', 'b', 'c')
        'c, b, a'
        >>> '{0}{1}{0}'.format('abra', 'cad')
        'abracadabra'
        >>> 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W') 
        'Coordinates: 37.24N, -115.81W'
        >>> coord = {'latitude': '37.24N', 'longitude': '-115.81W'}
        >>> 'Coordinates: {latitude}, {longitude}'.format(**coord)
        'Coordinates: 37.24N, -115.81W'
        >>> coord = (3, 5)
        >>> 'X: {0[0]};  Y: {0[1]}'.format(coord)
        'X: 3;  Y: 5'
        >>> str = 'HOW {0} {1} WORKS'
        >>> print(str.format("Python", 3))
        HOW Python 3 WORKS
        >>> str = 'HOW {soft} {Version} WORKS'
        >>> print(str.format(soft = 'Python', Version = 2.7))
        HOW Python 2.7 WORKS
        """
        pass
    def format_map(self, mapping): # real signature unknown; restored from __doc__
        """
        S.format_map(mapping) -> str
         
        執行字符串格式化操做,替換字段使用{}分隔,同str.format(**mapping), 除了直接使用mapping,而不復制到一個dict; (Python3新增)
        例如:
        >>> str = 'HOW {soft} {Version} WORKS'
        >>> soft = 'Python'
        >>> Version = 2.7
        >>> print (str.format_map(vars()))
        HOW Python 2.7 WORKS
        """
        return ""
    def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.index(sub [,start [,end]]) -> int
         
        檢測字符串中是否包含子字符串str,若是指定beg(開始)和end(結束)範圍,則檢查是否包含在指定範圍內,該方法與python find()方法同樣,只不過若是str不在string中會報一個異常;即str參數指定檢索的字符串;beg參數指開始索引,默認爲0;end參數指結束索引,默認爲字符串的長度;
        例如:
        >>> str = 'this is string example!'
        >>> print str.index('ex')
        15
        >>> print str.index('ex',10)
        15
        >>> print str.index('ex',40)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        ValueError: substring not found
        """
        return 0
    def isalnum(self): # real signature unknown; restored from __doc__
        """
        S.isalnum() -> bool
         
        檢測字符串是否由字母和數字組成,返回布爾值;
        例如:
        >>> str = 'this2009'
        >>> print str.isalnum()
        True
        >>> str = 'this is string example!'
        >>> print str.isalnum()
        False
        """
        return False
    def isalpha(self): # real signature unknown; restored from __doc__
        """
        S.isalpha() -> bool
         
        檢測字符串是否只由字母組成,返回布爾值,全部字符都是字母則返回 True,不然返回 False;
        例如:
        >>> str = 'this2009'
        >>> print str.isalpha()
        False
        >>> str = 'this is string example'
        >>> print str.isalpha()
        False
        >>> str = 'this'
        >>> print str.isalpha()
        True
        """
        return False
    def isdecimal(self): # real signature unknown; restored from __doc__
        """
        S.isdecimal() -> bool
         
        檢查字符串是否只包含十進制字符,這種方法只存在於unicode對象,返回布爾值,若是字符串是否只包含十進制字符返回True,不然返回False; (Python3新增)
        注:定義一個十進制字符串,只須要在字符串前添加'u'前綴便可;
        例如:
        >>> str = u'this2009'
        >>> print (str.isdecimal())
        False
        >>> str = u'22342009'
        >>> print (str.isdecimal())
        True
        """
        return False
    def isidentifier(self): # real signature unknown; restored from __doc__
        """
        S.isidentifier() -> bool
        判斷字符串是不是合法的標識符,字符串僅包含中文字符合法,實際上這裏判斷的是變量名是否合法,返回布爾值; (Python3新增)        
        例如:
        >>> str = 'Python3'
        >>> print(str.isidentifier())
        True
        >>> str = '_123'
        >>> print(str.isidentifier())
        True
        >>> str = '123'
        >>> print(str.isidentifier())
        False
        >>> str = ''
        >>> print(str.isidentifier())
        False
        >>> str = '123_'
        >>> print(str.isidentifier())
        False
        >>> str = '#123'
        >>> print(str.isidentifier())
        False
        >>> str = 'a123_'
        >>> print(str.isidentifier())
        True
        >>> #123 = 'a'
        ...
        >>> 123_ = 'a'
          File "<stdin>", line 1
             123_ = 'a'
               ^
        SyntaxError: invalid token
        """
        return False
    def isdigit(self): # real signature unknown; restored from __doc__
        """
        S.isdigit() -> bool
         
        檢測字符串是否只由數字組成,返回布爾值,若是字符串只包含數字則返回 True 不然返回 False;
        例如:
        >>> str = '123456'
        >>> print str.isdigit()
        True
        >>> str = 'this is string example!'
        >>> print str.isdigit()
        False
        """
        return False
    def islower(self): # real signature unknown; restored from __doc__
        """
        S.islower() -> bool
         
        檢測字符串是否由小寫字母組成,返回布爾值,全部字符都是小寫,則返回True,不然返回False;
        例如:
        >>> str = 'this is string example!'
        >>> print str.islower()
        True
        >>> str = 'This is string example!'
        >>> print str.islower()
        False
        """
        return False
    def isnumeric(self): # real signature unknown; restored from __doc__
        """
        S.isnumeric() -> bool
         
        檢測字符串是否只由數字組成,這種方法是隻針對unicode對象,返回布爾值,若是字符串中只包含數字字符,則返回True,不然返回False; (Python3新增)
        注:定義一個字符串爲Unicode,只須要在字符串前添加'u'前綴便可;
        例如:
        >>> str = u'this2009'
        >>> print (str.isnumeric())
        False
        >>> str = u'22342009'
        >>> print (str.isnumeric())
        True
        """
        return False
    def isprintable(self): # real signature unknown; restored from __doc__
        """
        S.isprintable() -> bool
         
        判斷字符串的全部字符都是可打印字符或字符串爲空,返回布爾值; (Python3新增)
        例如:
        >>> str = 'abc123'
        >>> print (str.isprintable())
        True
        >>> str = '123\t'
        >>> print (str.isprintable())
        False
        >>> str = ''
        >>> print (str.isprintable())
        True
                    
        """
        return False        
     def isspace(self): # real signature unknown; restored from __doc__
        """
        S.isspace() -> bool
         
        檢測字符串是否只由空格組成,返回布爾值,字符串中只包含空格,則返回True,不然返回False;
        例如:
        >>> str = ' '
        >>> print str.isspace()
        True
        >>> str = 'This is string example!'
        >>> print str.isspace()
        False
        """
        return False
    def istitle(self): # real signature unknown; restored from __doc__
        """
        S.istitle() -> bool
         
        檢測字符串中全部的單詞拼寫首字母是否爲大寫,且其餘字母爲小寫,返回布爾值,若是字符串中全部的單詞拼寫首字母是否爲大寫,且其餘字母爲小寫則返回True,不然返回False;
        例如:
        >>> str = 'This Is String Example!'
        >>> print (str.istitle())
        True
        >>> str = 'This Is String example!'
        >>> print (str.istitle())
        False
        """
        return False
    def isupper(self): # real signature unknown; restored from __doc__
        """
        S.isupper() -> bool
         
        檢測字符串中全部的字母是否都爲大寫,返回布爾值,若是字符串中包含至少一個區分大小寫的字符,而且全部這些(區分大小寫的)字符都是大寫,則返回True,不然返回False;
        例如:
        >>> str = 'THIS IS STRING EXAMPLE!'
        >>> print (str.isupper())
        True
        >>> str = 'This Is String example!'
        >>> print (str.istitle())
        False
        """
        return False
    def join(self, iterable): # real signature unknown; restored from __doc__
        """
        S.join(iterable) -> string
         
        用於將序列中的元素以指定的字符鏈接生成一個新的字符串,其中sequence參數指要鏈接的元素序列;
        例如:
        >>> str1 = '-'
        >>> str2 = ('a','b','c')
        >>> print str1.join(str2)
        a-b-c
        """
        return ""
    def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
        """
        S.ljust(width[, fillchar]) -> string
         
        返回一個原字符串左對齊,並使用空格填充至指定長度的新字符串,若是指定的長度小於原字符串的長度則返回原字符串,其中width參數指指定字符串長度,fillchar參數指填充字符,默認爲空格;
        >>> str = 'This Is String example!'
        >>> print str.ljust(50,'0')
        This Is String example!000000000000000000000000000
        """
        return ""
    def lower(self): # real signature unknown; restored from __doc__
        """
        S.lower() -> string
         
        轉換字符串中全部大寫字符爲小寫,返回將字符串中全部大寫字符轉換爲小寫後生成的字符串;
        例如:
        >>> str = 'THIS IS STRING EXAMPLE!'
        >>> print str.lower()
        this is string example!
        """
        return ""
    def maketrans(self, *args, **kwargs): # real signature unknown
        """
        Return a translation table usable for str.translate().
         
        用於建立字符映射的轉換表,並經過str.translate()進行返回,對於接受兩個參數的最簡單的調用方式,第一個參數是字符串,表示須要轉換的字符,第二個參數也是字符串表示轉換的目標;即intab參數指字符串中要替代的字符組成的字符串,outtab參數指相應的映射字符的字符串; (Python3新增)    
        注:兩個字符串的長度必須相同,爲一一對應的關係;
        例如:
        >>> str = 'this is string example!'
        >>> intab = 'aeiou'
        >>> outtab = '12345'
        >>> tarn = str.maketrans(intab,outtab)
        >>> print (str.translate(tarn))
        th3s 3s str3ng 2x1mpl2!
        >>> tarn = str.maketrans('aeiou','12345')
        >>> print (str.translate(tarn))
        th3s 3s str3ng 2x1mpl2!
        """
        pass
    def lstrip(self, chars=None): # real signature unknown; restored from __doc__
        """
        S.lstrip([chars]) -> string or unicode
         
        用於截掉字符串左邊的空格或指定字符,返回截掉字符串左邊的空格或指定字符後生成的新字符串,其中chars參數指指定截取的字符;
        例如:
        >>> str = '        This Is String example!'
        >>> print str.lstrip()
        This Is String example!
        >>> str = '88888888This Is String example!88888888'
        >>> print str.lstrip('8')
        This Is String example!88888888
        """
        return ""
    def partition(self, sep): # real signature unknown; restored from __doc__
        """
        S.partition(sep) -> (head, sep, tail)
         
        用來根據指定的分隔符將字符串進行分割,若是字符串包含指定的分隔符,則返回一個3元的元組,第一個爲分隔符左邊的子串,第二個爲分隔符自己,第三個爲分隔符右邊的子串;其中sep參數指指定的分隔符;
        例如:
        >>> str = 'http://434727.blog.51cto.com/'
        >>> print str.partition('://')
        ('http', '://', '434727.blog.51cto.com/')
        """
        pass
    def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
        """
        S.replace(old, new[, count]) -> string
         
        把字符串中的old(舊字符串)替換成new(新字符串),若是指定第三個參數count,則替換不超過count次;
        >>> str = 'this is string example! this is really string'
        >>> print str.replace('is', 'was')
        thwas was string example! thwas was really string
        >>> print str.replace('is', 'was',3)
        thwas was string example! thwas is really string
        """
        return ""
    def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.rfind(sub [,start [,end]]) -> int
         
        返回字符串最後一次出現的位置,若是沒有匹配項則返回-1,其中sub參數指查找的字符串;beg參數指開始查找的位置,默認爲0;end參數指結束查找位置,默認爲字符串的長度;
        例如:
        >>> str = 'this is string example!'
        >>> print str.rfind('is')
        5
        >>> print str.rfind('is',0,10)
        5
        >>> print str.rfind('is',10,0)
        -1
        """
        return 0
    def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.rindex(sub [,start [,end]]) -> int
         
        返回子字符串在字符串中最後出現的位置,若是沒有匹配的字符串會報異常,其中sub參數指查找的字符串;beg參數指開始查找的位置,默認爲0;end 參數指結束查找位置,默認爲字符串的長度;
        例如:
        >>> str = 'this is string example!'
        >>> print str.rindex('is')
        5
        >>> print str.rindex('is',0,10)
        5
        >>> print str.rindex('is',10,0)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          ValueError: substring not found
        """
        return 0
    def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
        """
        S.rjust(width[, fillchar]) -> string
         
        返回一個原字符串右對齊,並使用空格填充至長度width的新字符串,若是指定的長度小於字符串的長度則返回原字符串;其中width參數指填充指定字符後中字符串的總長度;fillchar參數指填充的字符,默認爲空格;
        例如:
        >>> str = 'this is string example!'
        >>> print str.rjust(50,'0')
        000000000000000000000000000this is string example!
        """
        return ""
    def rpartition(self, sep): # real signature unknown; restored from __doc__
        """
        S.rpartition(sep) -> (head, sep, tail)
         
        從後往前查找,返回包含字符串中分隔符以前、分隔符、分隔符以後的子字符串的元組;若是沒找到分隔符,返回字符串和兩個空字符串;
        例如:
        >>> str = 'this is string example!'
        >>> print str.rpartition('st')
        ('this is ', 'st', 'ring example!')
        >>> print str.rpartition('is')
        ('this ', 'is', ' string example!')
        >>> print str.rpartition('py')
        ('', '', 'this is string example!')
        """
        pass
    def rsplit(self, sep=None, maxsplit=None): # real signature unknown; restored from __doc__
        """
        S.rsplit([sep [,maxsplit]]) -> list of strings
         
        從後往前按照指定的分隔符對字符串進行切片,返回一個列表,其中sep參數指分隔符,默認爲空格;maxsplit參數指最多分拆次數;
        例如:
        >>> str = 'this is string example!'
        >>> print str.rsplit()
        ['this', 'is', 'string', 'example!']
        >>> print str.rsplit('st')
        ['this is ', 'ring example!']
        >>> print str.rsplit('is')
        ['th', ' ', ' string example!']
        >>> print str.rsplit('is',1)
        ['this ', ' string example!']
        """
        return []
    def rstrip(self, chars=None): # real signature unknown; restored from __doc__
        """
        S.rstrip([chars]) -> string or unicode
         
        刪除string字符串末尾的指定字符(默認爲空格),返回刪除string字符串末尾的指定字符後生成的新字符串,其中chars參數指刪除的字符(默認爲空格);
        例如:
        >>> str = '     this is string example!     '
        >>> print str.rstrip()
             this is string example!
        >>> str = '88888888this is string example!88888888'
        >>> print str.rstrip('8')
        88888888this is string example!
        """
        return ""
    def split(self, sep=None, maxsplit=None): # real signature unknown; restored from __doc__
        """
        S.split([sep [,maxsplit]]) -> list of strings
         
        經過指定分隔符對字符串進行切片,若是參數maxsplit有指定值,則僅分隔maxsplit個子字符串;其中sep參數指分隔符,默認爲全部的空字符,包括空格、換行(\n)、製表符(\t)等;maxsplit參數指分割次數;
        例如:
        >>> str = 'Line1-abcdef \nLine2-abc \nLine4-abcd'
        >>> print str.split()
        ['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
        >>> print str.split(' ',1)
        ['Line1-abcdef', '\nLine2-abc \nLine4-abcd']
        """
        return []
    def splitlines(self, keepends=False): # real signature unknown; restored from __doc__
        """
        S.splitlines(keepends=False) -> list of strings
         
        按照行('\r', '\r\n', \n')分隔,返回一個包含各行做爲元素的列表,若是參數keepends爲 False,不包含換行符,若是爲True,則保留換行符,返回一個包含各行做爲元素的列表;其中keepends參數指在輸出結果裏是否去掉換行符('\r', '\r\n', \n'),默認爲 False,不包含換行符,若是爲 True,則保留換行符;
        例如:
        >>> str1 = 'ab c\n\nde fg\rkl\r\n'
        >>> print str1.splitlines()
        ['ab c', '', 'de fg', 'kl']
        >>> str2 = 'ab c\n\nde fg\rkl\r\n'
        >>> print str2.splitlines(True)
        ['ab c\n', '\n', 'de fg\r', 'kl\r\n']
        """
        return []
    def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.startswith(prefix[, start[, end]]) -> bool
         
        用於檢查字符串是不是以指定子字符串開頭,若是是則返回True,不然返回False,若是參數beg和end指定了值,則在指定範圍內檢查;其中prefix參數指檢測的字符串;start參數用於設置字符串檢測的起始位置;end參數用於設置字符串檢測的結束位置;
        例如:
        >>> str = 'this is string example!'
        >>> print str.startswith('this')
        True
        >>> print str.startswith('is',2,4)
        True
        >>> print str.startswith('this',2,4)
        False
        """
        return False
    def strip(self, chars=None): # real signature unknown; restored from __doc__
        """
        S.strip([chars]) -> string or unicode
         
        用於移除字符串頭尾指定的字符(默認爲空格),返回移除字符串頭尾指定的字符生成的新字符串;其中chars參數指移除字符串頭尾指定的字符;
        例如:
        >>> str = '88888888this is string example!88888888'
        >>> print str.strip('8')
        this is string example!
        """
        return ""
    def swapcase(self): # real signature unknown; restored from __doc__
        """
        S.swapcase() -> string
         
        用於對字符串的大小寫字母進行轉換,返回大小寫字母轉換後生成的新字符串;
        例如:
        >>> str = 'this is string example!'
        >>> print str.swapcase()
        THIS IS STRING EXAMPLE!
        """
        return ""
    def title(self): # real signature unknown; restored from __doc__
        """
        S.title() -> string
         
        返回"標題化"的字符串,就是說全部單詞都是以大寫開始,其他字母均爲小寫;
        例如:
        >>> str = 'this is string example!'
        >>> print str.title()
        This Is String Example!
        """
        return ""
    def translate(self, table, deletechars=None): # real signature unknown; restored from __doc__
        """
        S.translate(table [,deletechars]) -> string
         
        根據參數table給出的表(包含256個字符)轉換字符串的字符, 要過濾掉的字符放到del參數中,返回翻譯後的字符串;其中table參數指翻譯表,翻譯表是經過maketrans方法轉換而來;deletechars參數指字符串中要過濾的字符列表;
        例如:
        >>> str = 'this is string example!'
        >>> intab = 'aeiou'
        >>> outtab = '12345'
        >>> tarn = str.maketrans(intab,outtab)
        >>> print (str.translate(tarn))
        th3s 3s str3ng 2x1mpl2!
        >>> tarn = str.maketrans('aeiou','12345')
        >>> print (str.translate(tarn))
        th3s 3s str3ng 2x1mpl2!
        """
        return ""
    def upper(self): # real signature unknown; restored from __doc__
        """
        S.upper() -> string
         
        將字符串中的小寫字母轉爲大寫字母,返回小寫字母轉爲大寫字母的字符串;
        例如:
        >>> str = 'this is string example!'
        >>> print str.upper()
        THIS IS STRING EXAMPLE!
        """
        return ""
    def zfill(self, width): # real signature unknown; restored from __doc__
        """
        S.zfill(width) -> string
         
        返回指定長度的字符串,原字符串右對齊,前面填充0,即width參數指定字符串的長度。原字符串右對齊,前面填充0;
        例如:
        >>> str = 'this is string example!'
        >>> print str.zfill(40)
        00000000000000000this is string example!
        """
        return ""
    def _formatter_field_name_split(self, *args, **kwargs): # real signature unknown
        """
         (Python2特有,Python3已刪除)
        """
        pass
    def _formatter_parser(self, *args, **kwargs): # real signature unknown
            """ 
         (Python2特有,Python3已刪除)
            """ 
        pass
    def __add__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__add__(y) 等同於 x+y 
         
        將兩個字符串相加,返回新的字符串;
        例如:
        >>> x = 'a'
        >>> y = 'b'
        >>> x.__add__(y)
        'ab'
        >>> x + y
        'ab'
        """
        pass
    def __contains__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__contains__(y) 等同於 y in x 
         
        字符串包含判斷,即判斷y是否包含在x中,返回布爾值;
        例如:
        >>> x = 'a'
        >>> y = 'b'
        >>> y in x
        False
        >>> x = 'ab'
        >>> y in x
        True
        """
        pass
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__eq__(y) 等同於 x==y 
         
        字符串等同於判斷,即判斷x是否等於y,返回布爾值;
        例如:
        >>> x = 'a'
        >>> y = 'b'
        >>> x == y
        False
        >>> y = 'a'
        >>> x == y
        True
        """
        pass
    def __format__(self, format_spec): # real signature unknown; restored from __doc__
        """
        S.__format__(format_spec) -> string
         
        格式化爲字符串;
        """
        return ""
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ 
        x.__getattribute__('name') 等同於 x.name 
        """
        pass
    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__getitem__(y) 等同於 x[y] 
         
        返回字符串指定下標的子字符串,下標值需指定併爲整數型,不然報錯;
        例如:
        >>> x = 'abc'
        >>> y = 1
        >>> x.__getitem__(y)
        'b'
        >>> x[y]
        'b'
        >>> x.__getitem__()
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: expected 1 arguments, got 0
        >>> x.__getitem__(1.1)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: string indices must be integers, not float
        """
        pass
    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass
    def __getslice__(self, i, j): # real signature unknown; restored from __doc__
        """
        x.__getslice__(i, j) 等同於 x[i:j]
                    
        返回字符串指定範圍的子字符串,i參數指開始位置,j參數指結束位置,i,j兩個參數必須同時存在,不指定或缺乏參數將報錯;(Python2特有,Python3已刪除)
        例如:
        >>> x = 'abcdefg'
        >>> x.__getslice__(1,4)
        'bcd'
        >>> x.__getslice__(1,0)
        ''
        >>> x.__getslice__()
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: function takes exactly 2 arguments (0 given)
        >>> x.__getslice__(1)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: function takes exactly 2 arguments (1 given)
        >>> x[1:4]
        'bcd'
        """
        pass
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ge__(y) 等同於 x>=y 
         
        字符串大小等於判斷,返回布爾值;
        例如:
        >>> x = 'abc'
        >>> y = 'ab'
        >>> x >= y
        True
        >>> y = 'abcd'
        >>> x >= y
        False
        """
        pass
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__gt__(y) 等於 x>y 
         
        字符串大於判斷,返回布爾值;
        例如:
        >>> x = 'abc'
        >>> y = 'ab'
        >>> x > y
        True
        >>> y = 'abcd'
        >>> x > y
        False
        """
        pass
    def __hash__(self): # real signature unknown; restored from __doc__
        """ 
        x.__hash__() 等同於 hash(x) 
         
        返回字符串的哈希值;
        例如:
        >>> x = 'abcd'
        >>> x.__hash__()
        1540938112
        >>> hash(x)
        1540938112
        """
        pass
    def __init__(self, string=''): # known special case of str.__init__
        """
        str(object='') -> string
         
        構造方法,執行x = 'abc'時自動調用str函數;
        """
        pass
    def __len__(self): # real signature unknown; restored from __doc__
        """ 
        x.__len__() 等同於 len(x) 
         
        返回字符串的長度;
        例如:
        >>> x = 'abcd'
        >>> x.__len__()
        4
        >>> len(x)
        4
        """
        pass
    def __iter__(self, *args, **kwargs): # real signature unknown
        """
        迭代對象,返回本身; (Python3新增)  
        """
        pass
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__le__(y) 等同於 x<=y 
         
        字符串小於等於判斷,返回布爾值;
        例如:
        >>> x = 'abc'
        >>> y = 'abcdef'
        >>> x .__le__(y)
        True
        >>> x <= y
        True
        >>> y = 'ab'
        >>> x <= y
        False
        """
        pass
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__lt__(y) 等同於 x<y 
         
        字符串小於判斷,返回布爾值;
        >>> x = 'abc'
        >>> y = 'abcdef'
        >>> x .__lt__(y)
        True
        >>> x < y
        True
        >>> y = 'ab'
        >>> x < y
        False
        """
        pass
    def __mod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__mod__(y) 等同於 x%y 
        """
        pass
    def __mul__(self, n): # real signature unknown; restored from __doc__
        """ 
        x.__mul__(n) 等同於 x*n 
         
        字符串乘法,n需爲整數,至關於n個字符串相加,新加入的字符串位置在原字符串後;
        例如:
        >>> x = 'abc'
        >>> n = 2
        >>> x.__mul__(n)
        'abcabc'
        >>> x * n
        'abcabc'
        """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ 
        T.__new__(S, ...) -> a new object with type S, a subtype of T 
        """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ne__(y) 等同於 x!=y 
         
        字符串不等於判斷,返回布爾值;
         
        """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ 
        x.__repr__() 等同於 repr(x) 
         
        轉化爲解釋器可讀取的形式,會使用""號將字符串包含起來;
        例如:
        >>> x = 'abcd'
        >>> x.__repr__()
        "'abcd'"
        >>> repr(x)
        "'abcd'"
        """
        pass
    def __rmod__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rmod__(y) 等同於 y%x 
        """
        pass
    def __rmul__(self, n): # real signature unknown; restored from __doc__
        """ 
        x.__rmul__(n) 等同於 n*x 
         
        字符串乘法,n需爲整數,至關於n個字符串相加,新加入的字符串位置在原字符串前;;
        """
        pass
    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ 
        S.__sizeof__() -> size of S in memory, in bytes 
         
        返回內存中的大小(以字節爲單位);
        """
        pass
    def __str__(self): # real signature unknown; restored from __doc__
        """ 
        x.__str__() <==> str(x) 
         
        轉換爲人閱讀的形式,若是沒有適於人閱讀的解釋形式的話,則返回解釋器課閱讀的形式;
        """
        pass
str

5、list的函數說明數組

列表能夠完成大多數集合類的數據結構實現,列表中元素的類型能夠不相同,它支持數字,字符串甚至能夠包含列表(所謂嵌套);列表是寫在方括號([])之間、用逗號分隔開的元素列表;和字符串同樣,列表一樣能夠被索引和截取,列表被截取後返回一個包含所需元素的新列表;安全

在python中列表提供的函數具體以下:數據結構

lass list(object):
    """
    list() -> 新的空列表;
    list(iterable) -> 從iterable參數中獲取值初始化成新的列表;
    """
    def append(self, p_object): # real signature unknown; restored from __doc__
        """ 
        L.append(object)
         
        用於在列表末尾添加新的對象,該方法無返回值,可是會修改原來的列表;其中self參數指添加到列表末尾的對象;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> alist.append( 2009 )
        >>> alist
        [123, 'xyz', 'zara', 'abc', 2009]
        """
        pass
        def clear(self): # real signature unknown; restored from __doc__
        """ 
        L.clear() -> None
         
        清空列表; (Python3新增) 
        例如:
        >>> alist = [11,22,33,44]
        >>> alist
        [11, 22, 33, 44]
        >>> alist.clear()
        >>> alist
        []
        """
        pass
 
    def copy(self): # real signature unknown; restored from __doc__
        """ 
        L.copy() -> list
         
        拷貝一個列表,此處是淺拷貝; (Python3新增)
        例如:
        >>> alist1 = [11,22,33,44]
        >>> alist2 = alist.copy()
        >>> alist2
        [11, 22, 33, 44]
        """
        return []    
    def count(self, value): # real signature unknown; restored from __doc__
        """ 
        L.count(value) -> integer
         
        用於統計某個元素在列表中出現的次數,返回整形,其中obj參數指列表中統計的對象;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc', 123]
        >>> print 'Count for 123 : ', alist.count(123)
        Count for 123 :  2
        >>> print 'Count for zara : ', alist.count('zara')
        Count for zara :  1
        """
        return 0
    def extend(self, iterable): # real signature unknown; restored from __doc__
        """ 
        L.extend(iterable) -- extend
         
        用於在列表末尾一次性追加另外一個序列中的多個值(用新列表擴展原來的列表),該方法沒有返回值,但會在已存在的列表中添加新的列表內容;其中iterable參數指元素列表;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> blist = [2009, 'manni']
        >>> alist.extend(blist)
        >>> alist
        [123, 'xyz', 'zara', 'abc', 2009, 'manni']        
        """
        pass
    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
        """
        L.index(value, [start, [stop]]) -> integer
         
        用於從列表中找出某個值第一個匹配項的索引位置,該方法返回查找對象的索引位置,若是沒有找到對象則拋出異常;其中value參數指檢索的字符串,start參數指檢索的起始位置,stop參數指檢索的結束位置;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> alist.index('xyz')
        1
        >>> alist.index('zara',1)
        2
        >>> alist.index('zara',1,5)
        2
        >>> alist.index('zara',1,0)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        ValueError: 'zara' is not in list
        """
        return 0
    def insert(self, index, p_object): # real signature unknown; restored from __doc__
        """
        L.insert(index, object)
         
        用於將指定對象插入列表的指定位置,該方法沒有返回值,會直接修改原有列表,其中index參數指插入的位置,object參數指插入的字符串,兩個參數需同時指定;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> alist
        [123, 'def', 'xyz', 'zara', 'abc']
        >>> alist.insert('def')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: insert() takes exactly 2 arguments (1 given)
        >>> alist.insert(1,'def')
        >>> alist.insert(2)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: insert() takes exactly 2 arguments (1 given)
        """
        pass
    def pop(self, index=None): # real signature unknown; restored from __doc__
        """
        L.pop([index]) -> item
         
        用於移除列表中的一個元素(默認最後一個元素),而且返回該元素的值,若是列表爲空或索引超出範圍,則引報錯;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> alist.pop()
        'abc'
        >>> alist
        [123, 'xyz', 'zara']
        >>> alist.pop(2)
        'zara'
        >>> alist
        [123, 'xyz']
        >>> alist.pop(123)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        IndexError: pop index out of range
        >>> alist = []
        >>> alist.pop()
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        IndexError: pop from empty list
        """
        pass
    def remove(self, value): # real signature unknown; restored from __doc__
        """
        L.remove(value)
         
        用於移除列表中某個值的第一個匹配項,該方法沒有返回值可是會移除兩種中的某個值的第一個匹配項;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc','xyz']
        >>> alist.remove('xyz')
        >>> alist
        [123, 'zara', 'abc', 'xyz']
        """
        pass
    def reverse(self): # real signature unknown; restored from __doc__
        """ 
        L.reverse()
         
        用於反向列表中元素,該方法沒有返回值,可是會對列表的元素進行反向排序;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> alist.reverse()
        >>> alist
        ['abc', 'zara', 'xyz', 123]
        """
        pass
    def sort(self, cmp=None, key=None, reverse=False): # real signature unknown; restored from __doc__
        """
        L.sort(cmp=None, key=None, reverse=False)
         
        用於對原列表進行排序,若是指定參數,則使用會使用該參數的方法進行排序,該方法沒有返回值,可是會對列表的對象進行排序;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> alist.sort()
        >>> alist
        [123, 'abc', 'xyz', 'zara']
        >>> alist.sort(reverse=True)
        >>> alist
        ['zara', 'xyz', 'abc', 123]
        """
        pass
    def __add__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__add__(y) 等同於 x+y 
         
        加法,將兩個列表值進行相加,並返回新的列表值;
        例如:
        >>> alist = [123, 'xyz', 'zara', 'abc']
        >>> blist = [456, 'wsx', 'edc']
        >>> alist.__add__(blist)
        [123, 'xyz', 'zara', 'abc', 456, 'wsx', 'edc']
        >>> alist + blist
        [123, 'xyz', 'zara', 'abc', 456, 'wsx', 'edc']
        """
        pass
    def __contains__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__contains__(y) 等同於 y in x 
         
        列表包含判斷,即判斷y是否包含在x中,返回布爾值;
        例如:
        >>> x = [ 11, 22, 33, 44 ]
        >>> y = 11
        >>> x.__contains__(y)
        True
        >>> y in x
        True
        >>> y = 55
        >>> x.__contains__(y)
        False
        >>> x = [ 11,[ 22, 33], 44]
        >>> y = [ 22, 33 ]
        >>> x.__contains__(y)
        True
        """
        pass
    def __delitem__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__delitem__(y) 等同於 del x[y] 
         
        用於移除列表中指定下標的一個元素,該方法沒有返回值,若是列表爲空或索引超出範圍,則引報錯;
        例如:
        >>> x = [11,22,33,44]
        >>> y = 2
        >>> x.__delitem__(y)
        >>> x
        [11, 22, 44]
        >>> del x[y]
        >>> x
        [11, 22]
        >>> x = []
        >>> del x[y]
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        IndexError: list assignment index out of range
        >>> y = 10
        >>> del x[y]
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        IndexError: list assignment index out of range
        """
        pass
    def __delslice__(self, i, j): # real signature unknown; restored from __doc__
        """
        x.__delslice__(i, j) 等同於 del x[i:j]
                    
        用於移除列表中指定下標範圍的元素,該方法沒有返回值,i參數指開始位置,j參數指結束位置,i,j兩個參數必須同時存在,不指定或缺乏參數將報錯;(Python2特有,Python3已刪除)
        例如:
        >>> x = [11,22,33,44,55]
        >>> x.__delslice__(1,3)
        >>> x
        [11, 44, 55]
        >>> x.__delslice__(4,5)
        >>> x
        [11, 44, 55]
        """
        pass
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__eq__(y) 等同於 x==y 
         
        列表等同於判斷,即判斷x是否等於y,返回布爾值;
        例如:
        >>> x = [11,22,33,44,55]
        >>> y = [66,77]
        >>> x.__eq__(y)
        False
        >>> x == y
        False
        >>> y = [11,22,33,44,55]
        >>> x == y
        True
        """
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ 
        x.__getattribute__('name') 等同於 x.name 
        """
        pass
    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__getitem__(y) 等同於 x[y] 
         
        返回列表指定下標的子字符串,並返回子字符串,下標值需指定併爲整數型,不然報錯;
        例如:
        >>> x = [11,22,33,44,55]
        >>> x.__getitem__(1)
        22
        """
        pass
    def __getslice__(self, i, j): # real signature unknown; restored from __doc__
        """
        x.__getslice__(i, j) 等同於 x[i:j]
                    
         
        返回列表指定範圍的子列表,i參數指開始位置,j參數指結束位置,i,j兩個參數必須同時存在,不指定或缺乏參數將報錯;(Python2特有,Python3已刪除)
        例如:
        >>> x = [11,22,33,44,55]
        >>> x.__getslice__(1,4)
        [22, 33, 44]
        >>> x
        [11, 22, 33, 44, 55]
        >>> x[1:4]
        [22, 33, 44]
        """
        pass
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ge__(y) 等同於 x>=y 
         
        列表大小等於判斷,返回布爾值;
        例如:
        >>> x = [11,22,33,44,55]
        >>> y = [11,22]
        >>> x.__ge__(y)
        True
        >>> x >= y
        True
        >>> y = [11,22,33,44,55]
        >>> x >= y
        True
        >>> y = [11,22,33,44,55,66]
        >>> x >= y
        False
        """
        pass
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__gt__(y) 等同於 x>y 
         
        列表大於判斷,返回布爾值;
        例如:
        >>> x = [11,22,33,44,55]
        >>> y = [11,22,33,44]
        >>> x.__gt__(y)
        True
        >>> x > y
        True
        >>> y = [11,22,33,44,55,66]
        >>> x > y
        False
        """
        pass
    def __iadd__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__iadd__(y) 等同於 x+=y 
         
        將第二個個列表加入到第一個列表,即將y的列表值加入x列表,使用x.__iadd__(y)方法會返回改變後的列表,使用x += y只會改變列表不會有返回值;
        例如:
        >>> x = [11,22,33,44]
        >>> y = [55,66]
        >>> x.__iadd__(y)
        [11, 22, 33, 44, 55, 66]
        >>> x
        [11, 22, 33, 44, 55, 66]
        >>> x += y
        >>> x
        [11, 22, 33, 44, 55, 66, 55, 66]
        """
        pass
    def __imul__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__imul__(y) 等同於 x*=y 
         
        列表乘法,y需爲整數,至關於y個列表進行相加,並改變原有列表;使用x.__imul__(y)方法會返回改變後的列表,使用x *= y只會改變列表不會有返回值;
        例如:
        >>> x = [11,22,33,44]
        >>> x.__imul__(2)
        [11, 22, 33, 44, 11, 22, 33, 44]
        >>> x
        [11, 22, 33, 44, 11, 22, 33, 44]
        >>> x *= 2
        >>> x
        [11, 22, 33, 44, 11, 22, 33, 44, 11, 22, 33, 44, 11, 22, 33, 44]
        """
        pass
    def __init__(self, seq=()): # known special case of list.__init__
        """
        list() -> new empty list
        list(iterable) -> new list initialized from iterable's items
         
        構造方法,執行x = []時自動調用list函數;
        """
        pass
    def __iter__(self): # real signature unknown; restored from __doc__
        """         
        x.__iter__() 等同於 iter(x) 
         
        迭代對象,返回本身;
        """
        pass
    def __len__(self): # real signature unknown; restored from __doc__
        """ 
        x.__len__() 等同於 len(x) 
         
        返回列表的長度;
        例如:
        >>> x = [11,22,33,44]
        >>> x.__len__()
        4
        >>> len(x)
        4
        """
        pass
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__le__(y) 等同於 x<=y 
         
        列表小於等於判斷,返回布爾值;
        """
        pass
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__lt__(y) 等同於 x<y 
        列表小於判斷,返回布爾值;
        """
        pass
    def __mul__(self, n): # real signature unknown; restored from __doc__
        """ 
        x.__mul__(n) 等同於 x*n 
         
        列表乘法,n需爲整數,至關於n個字符串相加,新加入的字符串位置在原字符串後,不會改變原有列表;
        例如:
        >>> x = [11,22,33,44]
        >>> x.__mul__(2)
        [11, 22, 33, 44, 11, 22, 33, 44]
        >>> x
        [11, 22, 33, 44]
        >>> x * 2
        [11, 22, 33, 44, 11, 22, 33, 44]
        >>> x
        [11, 22, 33, 44]
        """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ 
        T.__new__(S, ...) -> a new object with type S, a subtype of T 
        """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ne__(y) 等同於 x!=y
         
        字符串不等於判斷,返回布爾值;         
        """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ 
        x.__repr__() 等同於 repr(x) 
         
        轉化爲解釋器可讀取的形式,即轉換爲字符串格式;
        """
        pass
    def __reversed__(self): # real signature unknown; restored from __doc__
        """ 
        L.__reversed__() -- return a reverse iterator over the list 
         
        返回一個反向迭代器;
        """
        pass
    def __rmul__(self, n): # real signature unknown; restored from __doc__
        """ 
        x.__rmul__(n) 等同於 n*x
         
        字符串乘法,n需爲整數,至關於n個字符串相加,新加入的字符串位置在原字符串前; 
        """
        pass
    def __setitem__(self, i, y): # real signature unknown; restored from __doc__
        """ 
        x.__setitem__(i, y) 等同於 x[i]=y
         
        將x列表指定的i下標值替換爲y,該方法直接改變x列表,但沒有返回值,
        例如:
        >>> x = [11,22,33,44]
        >>> y = []
        >>> x.__setitem__(2,y)
        >>> x
        [11, 22, [], 44]
        >>> y = [55,66]
        >>> x[2]= y
        >>> x
        [11, 22, [55, 66], 44] 
        """
        pass
    def __setslice__(self, i, j, y): # real signature unknown; restored from __doc__
        """
        x.__setslice__(i, j, y) 等同於 x[i:j]=y                    
         
        將x列表指定下標範圍對應的值,修改成y,i參數指開始位置,j參數指結束位置,i,j兩個參數必須同時存在,不指定或缺乏參數將報錯;(Python2特有,Python3已刪除)
        例如:
        >>> x = [11,22,33,44,55,66]
        >>> y = [99,100]
        >>> x.__setslice__(1,4,y)
        >>> x
        [11, 99, 100, 55, 66]
        >>> x = [11,22,33,44,55,66]
        >>> x[0:3] = y
        >>> x
        [99, 100, 44, 55, 66]
        >>> x = [11,22,33,44,55,66]
        >>> x[0:0] = y
        >>> x
        [99, 100, 11, 22, 33, 44, 55, 66]
        """
        pass
    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ 
        L.__sizeof__() -- size of L in memory, in bytes 
         
        返回內存中的大小(以字節爲單位);
        """
        pass
    __hash__ = None
list

6、元組的函數說明(元組至關於不能修改的列表,其只有只讀屬性沒有修改的屬性,使用方法與list函數一致)多線程

元組(tuple)與列表相似,不一樣之處在於元組的元素不能修改,元組寫在小括號(())裏,元素之間用逗號隔開;

在python中元組提供的函數以下:

class tuple(object):
    """
    tuple() -> empty tuple
    tuple(iterable) -> tuple initialized from iterable's items
     
    If the argument is a tuple, the return value is the same object.
    """
    def count(self, value): # real signature unknown; restored from __doc__
        """ T.count(value) -> integer -- return number of occurrences of value """
        return 0
    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
        """
        T.index(value, [start, [stop]]) -> integer -- return first index of value.
        Raises ValueError if the value is not present.
        """
        return 0
    def __add__(self, y): # real signature unknown; restored from __doc__
        """ x.__add__(y) <==> x+y """
        pass
    def __contains__(self, y): # real signature unknown; restored from __doc__
        """ x.__contains__(y) <==> y in x """
        pass
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ x.__eq__(y) <==> x==y """
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass
    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__getitem__(y) <==> x[y] """
        pass
    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass
    def __getslice__(self, i, j): # real signature unknown; restored from __doc__
        """
        x.__getslice__(i, j) <==> x[i:j]
                    
        Use of negative indices is not supported. (Python2特有,Python3已刪除)
        """
        pass
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ x.__ge__(y) <==> x>=y """
        pass
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ x.__gt__(y) <==> x>y """
        pass
    def __hash__(self): # real signature unknown; restored from __doc__
        """ x.__hash__() <==> hash(x) """
        pass
    def __init__(self, seq=()): # known special case of tuple.__init__
        """
        tuple() -> empty tuple
        tuple(iterable) -> tuple initialized from iterable's items
         
        If the argument is a tuple, the return value is the same object.
        # (copied from class doc)
        """
        pass
    def __iter__(self): # real signature unknown; restored from __doc__
        """ x.__iter__() <==> iter(x) """
        pass
    def __len__(self): # real signature unknown; restored from __doc__
        """ x.__len__() <==> len(x) """
        pass
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ x.__le__(y) <==> x<=y """
        pass
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ x.__lt__(y) <==> x<y """
        pass
    def __mul__(self, n): # real signature unknown; restored from __doc__
        """ x.__mul__(n) <==> x*n """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ x.__ne__(y) <==> x!=y """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass
    def __rmul__(self, n): # real signature unknown; restored from __doc__
        """ x.__rmul__(n) <==> n*x """
        pass
tuple

7、字典的函數說明

字典(dictionary)是Python中另外一個很是有用的內置數據類型,列表是有序的對象結合,字典是無序的對象集合,二者之間的區別在於:字典當中的元素是經過鍵來存取的,而不是經過偏移存取; 

字典是一種映射類型,字典用"{ }"標識,它是一個無序的鍵(key) : 值(value)對集合,鍵(key)必須使用不可變類型,在同一個字典中,鍵(key)必須是惟一的; 

python中字典提供的函數以下:

class dict(object):
    """
    dict() -> 新的空字典
    dict(mapping) -> 從(key, value)獲取值,並初始化的新字典;
    dict(iterable) -> 也可經過如下方法初始化新字典:
        d = {}
        for k, v in iterable:
            d[k] = v
    dict(**kwargs) -> 使用name=value方法初始化新字典;
            For example:  dict(one=1, two=2)
    """
    def clear(self): # real signature unknown; restored from __doc__
        """ 
        D.clear() -> None.
        清空字典;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.clear()
        >>> x
        {}
        """
        pass
    def copy(self): # real signature unknown; restored from __doc__
        """ 
        D.copy() -> a shallow copy of D 
         
        拷貝一個字典,此處是淺拷貝;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.copy()
        >>> y
        {'k2': 'v2', 'k1': 'v1'}
        """
        pass
    @staticmethod # known case
    def fromkeys(S, v=None): # real signature unknown; restored from __doc__
        """
        dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
        v defaults to None.
         
        建立並返回一個新字典,以S中的元素作該字典的鍵,v作該字典中全部鍵對應的初始值(默認爲None);
        例如:
        >>> x = [ 'k1','k2','k3']
        >>> y = {}
        >>> y.fromkeys(x,'v1')
        {'k3': 'v1', 'k2': 'v1', 'k1': 'v1'}
        >>> y
        {}
        """
        pass
    def get(self, k, d=None): # real signature unknown; restored from __doc__
        """ 
        D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None. 
         
        返回字典中key對應的值,若key不存在字典中,則返回default的值(default默認爲None)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.get('k2')
        >>> y
        'v2'
        >>> y = x.get('k3','v3')
        >>> y
        'v3'
        """
        pass
    def has_key(self, k): # real signature unknown; restored from __doc__
        """ 
        D.has_key(k) -> True if D has a key k, else False 
         
        檢查字典是否存在指定的key; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.has_key('k1')
        True
        >>> x.has_key('v1')
        False
        >>> x.has_key('k3')
        False
        """
        return False
    def items(self): # real signature unknown; restored from __doc__
        """ 
        D.items() -> list of D's (key, value) pairs, as 2-tuples 
         
        返回一個包含全部(key, value)元祖的列表;
         
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.items()
        >>> y
        [('k2', 'v2'), ('k1', 'v1')]
        """
        return []
    def iteritems(self): # real signature unknown; restored from __doc__
        """ 
        D.iteritems() -> an iterator over the (key, value) items of D 
         
        字典項可迭代,方法在須要迭代結果的時候使用最適合,並且它的工做效率很是的高; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.iteritems()
        >>> y
        <dictionary-itemiterator object at 0x02B0EEA0>
        >>> type(y)
        <type 'dictionary-itemiterator'>
        >>> list(y)
        [('k2', 'v2'), ('k1', 'v1')]
        """
        pass
    def iterkeys(self): # real signature unknown; restored from __doc__
        """ 
        D.iterkeys() -> an iterator over the keys of D 
         
        key可迭代; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.iterkeys()
        >>> y
        <dictionary-keyiterator object at 0x030CACF0>
        >>> type(y)
        <type 'dictionary-keyiterator'>
        >>> list(y)
        ['k2', 'k1']        
        """
        pass
    def itervalues(self): # real signature unknown; restored from __doc__
        """ 
        D.itervalues() -> an iterator over the values of D 
         
        value可迭代; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.itervalues()
        >>> y
        <dictionary-valueiterator object at 0x031096F0>
        >>> type(y)
        <type 'dictionary-valueiterator'>
        >>> list(y)
        ['v2', 'v1']
        """
        pass
    def keys(self): # real signature unknown; restored from __doc__
        """ 
        D.keys() -> list of D's keys 
         
        返回一個包含字典全部key的列表;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.keys()
        ['k2', 'k1']
        """
        return []
    def pop(self, k, d=None): # real signature unknown; restored from __doc__
        """
        D.pop(k[,d]) -> v
         
        彈出指定key值的元素(由於字典是無序的,因此必須指定key值),會改變原有字典,並返回彈出key的value,若是key不存在,則報錯;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.pop('k1')
        'v1'
        >>> x
        {'k2': 'v2'}
        >>> x.pop('k3')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'k3'
        """
        pass
    def popitem(self): # real signature unknown; restored from __doc__
        """
        D.popitem() -> (k, v)
         
        按照內存順序刪除字典;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.popitem()
        ('k2', 'v2')
        >>> x.popitem()
        ('k1', 'v1')
        >>> x.popitem()
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'popitem(): dictionary is empty'
        """
        pass
    def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
        """ 
        D.setdefault(k[,d]) -> D.get(k,d)
         
        設置字典key鍵,若是字典已存在key鍵,則不改變key鍵,並返回原有key鍵的value值,若是字典中不存在Key鍵,由爲它賦值;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.setdefault('k3','v3')
        'v3'
        >>> x
        {'k3': 'v3', 'k2': 'v2', 'k1': 'v1'}
        >>> x.setdefault('k1','v3')
        'v1'
        >>> x
        {'k3': 'v3', 'k2': 'v2', 'k1': 'v1'}
        """
        pass
    def update(self, E=None, **F): # known special case of dict.update
        """
        D.update([E, ]**F) -> None.
         
        更新字典;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.update({'k3':'v3'})
        >>> x
        {'k3': 'v3', 'k2': 'v2', 'k1': 'v1'}
        """
        pass
    def values(self): # real signature unknown; restored from __doc__
        """ 
        D.values() -> list of D's values
         
        獲取字典中的值,返回列表;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.values()
        ['v2', 'v1']
        """
        return []
    def viewitems(self): # real signature unknown; restored from __doc__
        """ 
        D.viewitems() -> a set-like object providing a view on D's items 
         
        爲字典D全部對象,提供相似集合的視圖; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.viewitems()
        dict_items([('k2', 'v2'), ('k1', 'v1')])
        """
        pass
    def viewkeys(self): # real signature unknown; restored from __doc__
        """ 
        D.viewkeys() -> a set-like object providing a view on D's keys 
         
        爲字典D的key,提供類型集合的視圖; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.viewkeys()
        dict_keys(['k2', 'k1']) 
        """
        pass
    def viewvalues(self): # real signature unknown; restored from __doc__
        """ 
        D.viewvalues() -> an object providing a view on D's values 
         
        爲字典D的values,提供類型集合的視圖; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = x.viewvalues()
        >>> y
        dict_values(['v2', 'v1'])
        """
        pass
    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__cmp__(y) 等同於 cmp(x,y) 
         
        用於比較兩個字典元素,若是兩個字典的元素相同返回0,若是字典x大於字典y返回1,若是字典x小於字典y返回-1; (Python2特有,Python3已刪除)
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> y = { 'k1':'v1','k2':'v2' }
        >>> z = { 'k1':'v3','k2':'v2' }
        >>> x.__cmp__(y)
        0
        >>> x.__cmp__(z)
        -1
        >>> y = { 'k1':0,'k2':'v2' }
        >>> x.__cmp__(y)
        1
        >>> cmp(x,y)
        1
        """
        pass
    def __contains__(self, k): # real signature unknown; restored from __doc__
        """ 
        D.__contains__(k) -> True if D has a key k, else False 
         
        字典包含判斷,即判斷y是否包含在x中,返回布爾值;
        """
        return False
    def __delitem__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__delitem__(y) 等同於 del x[y] 
         
        用於移除列表中指定key的元素,該方法沒有返回值,若是字典爲空或索引超出範圍,則引報錯;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.__delitem__('k1')
        >>> x
        {'k2': 'v2'}
        >>> x.__delitem__('k3')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'k3'
        """
        pass
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__eq__(y) 等同於 x==y 
         
        字典等同於判斷,即判斷x是否等於y,返回布爾值;
        """
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ 
        x.__getattribute__('name') 等同於 x.name 
        """
        pass
    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__getitem__(y) 等同於 x[y] 
         
        返回字典指定key的value,並返回value,key值需存在於字典,不然報錯;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.__getitem__('k1')
        'v1'
        >>> x.__getitem__('k3')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'k3'
        """
        pass
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ge__(y) 等同於 x>=y
         
        字典大於等於判斷,返回布爾值; 
        """
        pass
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__gt__(y) 等同於 x>y
         
        字典大於判斷,返回布爾值; 
        """
        pass
    def __init__(self, seq=None, **kwargs): # known special case of dict.__init__
        """
        dict() -> new empty dictionary
        dict(mapping) -> new dictionary initialized from a mapping object's
            (key, value) pairs
        dict(iterable) -> new dictionary initialized as if via:
            d = {}
            for k, v in iterable:
                d[k] = v
        dict(**kwargs) -> new dictionary initialized with the name=value pairs
            in the keyword argument list.  For example:  dict(one=1, two=2)
        構造方法,執行x = {}時自動調用字典函數;
        """
        pass
    def __iter__(self): # real signature unknown; restored from __doc__
        """ 
        x.__iter__() 等同於 iter(x)
         
        迭代對象,返回本身; 
        """
        pass
    def __len__(self): # real signature unknown; restored from __doc__
        """ 
        x.__len__() 等同於 len(x) 
         
        返回字典的長度;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.__len__()
        2
        >>> len(x)
        2
        """
        pass
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__le__(y) 等同於 x<=y 
         
        字典小於等於判斷,返回布爾值;
        """
        pass
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__lt__(y) <==> x<y 
         
        字典小於判斷,返回布爾值;
        """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ 
        T.__new__(S, ...) -> a new object with type S, a subtype of T 
        """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ne__(y) 等同於 x!=y 
         
        字典不等於判斷,返回布爾值;
        """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ 
        x.__repr__() 等同於 repr(x) 
         
        轉化爲解釋器可讀取的形式,即轉換爲字符串格式;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.__repr__()
        "{'k2': 'v2', 'k1': 'v1'}"
        >>> x
        {'k2': 'v2', 'k1': 'v1'}
        >>> repr(x)
        "{'k2': 'v2', 'k1': 'v1'}"
        """
        pass
    def __setitem__(self, i, y): # real signature unknown; restored from __doc__
        """ 
        x.__setitem__(i, y) 等同於 x[i]=y 
         
        將x字典指定key的value值替換爲y,該方法直接改變x字典,但沒有返回值;
        例如:
        >>> x = { 'k1':'v1','k2':'v2' }
        >>> x.__setitem__('k1','v3')
        >>> x
        {'k2': 'v2', 'k1': 'v3'}       
        """
        pass
    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ 
        D.__sizeof__() -> size of D in memory, in bytes 
         
        返回內存中的大小(以字節爲單位);
        """
        pass
    __hash__ = None
dict

8、set的函數說明

集合(set)是一個無序不重複元素的序列,基本功能是進行成員關係測試和刪除重複元素,可使用大括號({})或者 set()函數建立集合;

注:建立一個空集合必須用set()而不是{ },由於{ }是用來建立一個空字典;

在python中set提供的函數以下: 

class set(object):
    """
    set() -> 空的新集合對象;
    set(iterable) -> 新的集合對象;
     
    Build an unordered collection of unique elements.
    """
    def add(self, *args, **kwargs): # real signature unknown
        """
         
        在集合中增長元素,若是添加元素已存在於集合,則無效;
        例如:
        >>> x = set()
        >>> x.add('x')
        >>> x
        set(['x'])
        """
        pass
    def clear(self, *args, **kwargs): # real signature unknown
        """
          
        清空集合;
        例如:
        >>> x = set(['k1','k2'])
        >>> x
        set(['k2', 'k1'])
        >>> x.clear()
        >>> x
        set([])
        """
        pass
    def copy(self, *args, **kwargs): # real signature unknown
        """ 
         
        集合的淺拷貝;
        例如:
        >>> x = set(['k1','k2'])
        >>> y = x.copy()
        >>> y
        set(['k2', 'k1'])
        """
        pass
    def difference(self, *args, **kwargs): # real signature unknown
        """
         
        獲取兩個集合的不一樣(差集),並生成一個新的集合;即獲取x.difference(y)的差集,至關於獲取x多餘y的集合值;
        若是x包含於y,則獲取空值;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> s3 = x.difference(y)
        >>> s3
        set(['c'])
        >>> s4 = y.difference(x)
        >>> s4
        set([])
        """
        pass
    def difference_update(self, *args, **kwargs): # real signature unknown
        """ 
         
        獲取兩個集合的不一樣(差集),改變原來的集合;即獲取x.difference_update(y)的差集,至關於獲取x多餘y的集合值,並重寫進x;
        若是x包含於y,則獲取空值,並重寫進x;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.difference_update(y)
        >>> x
        set(['c'])
        >>> y
        set(['a', 'b'])
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> y.difference_update(x)
        >>> y
        set([])
        >>> x
        set(['a', 'c', 'b'])
        """
        pass
    def discard(self, *args, **kwargs): # real signature unknown
        """
         
        移除集合中的一個指定元素,若是這個元素不存在,則不變;
        例如:
        >>> x = set(['a','b','c'])
        >>> x.discard('a')
        >>> x
        set(['c', 'b'])
        >>> x.discard('d')
        >>> x
        set(['c', 'b'])
        """
        pass
    def intersection(self, *args, **kwargs): # real signature unknown
        """
         
        獲取兩個集合的交集,生成一個新的集合;即獲取x.intersection(y)的交集,至關於獲取x與y相等的那部分集合值;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.intersection(y)
        set(['a', 'b'])
        >>> x
        set(['a', 'c', 'b'])
        >>> y
        set(['a', 'b'])
        """
        pass
    def intersection_update(self, *args, **kwargs): # real signature unknown
        """
         
        獲取兩個集合的交集,改變原來的集合; 即獲取x.intersection_update(y)的交集,至關於獲取x與y相等的那部分集合值,並重寫進x;
        若是x包含於y,則無變化;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.intersection_update(y)
        >>> x
        set(['a', 'b'])
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> y.intersection_update(x)
        >>> y
        set(['a', 'b'])
        >>> x
        set(['a', 'c', 'b'])
        """
        pass
    def isdisjoint(self, *args, **kwargs): # real signature unknown
        """
         
        判斷兩個集合是否沒有交集,若是是返回True,若是不是返回False;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.isdisjoint(y)
        False
        >>> y = set(['d'])
        >>> x.isdisjoint(y)
        True
        """
        pass
    def issubset(self, *args, **kwargs): # real signature unknown
        """
         
        判斷一個集合是不是另外一個集合的子集; 即x.issubset(y),至關於判斷x是否y的子集;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.issubset(y)
        False
        >>> y.issubset(x)
        True
        """
        pass
    def issuperset(self, *args, **kwargs): # real signature unknown
        """
         
        判斷一個集合是否包含另外一個集合;即x.issuperset(y),至關於判斷x是否包含y;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.issuperset(y)
        True
        >>> y.issuperset(x)
        False
        """
        pass
    def pop(self, *args, **kwargs): # real signature unknown
        """
         
        刪除並返回任意設置的元素,若是集合爲空,則引起KeyError;
        例如:
        >>> x = set(['a','b','c'])
        >>> x.pop()
        'a'
        >>> x.pop()
        'c'
        >>> x.pop()
        'b'
        >>> x.pop()
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'pop from an empty set'
        """
        pass
    def remove(self, *args, **kwargs): # real signature unknown
        """
         
        移除集合中指定的元素,若是集合爲空或指定的元素不存在,則引起KeyError;
        例如:
        >>> x = set(['a','b','c'])
        >>> x.remove('b')
        >>> x
        set(['a', 'c'])
        >>> x.remove('d')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'd'
        """
        pass
    def symmetric_difference(self, *args, **kwargs): # real signature unknown
        """
         
        把兩個集合中的不一樣元素,即差集,放到一個新的集合中;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.symmetric_difference(y)
        set(['a', 'b', 'd'])
        """
        pass
    def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
        """
         
        兩個集合不相同的元素,即差集,並改變原集合;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.symmetric_difference_update(y)
        >>> x
        set(['a', 'b', 'd'])
        >>> y
        set(['c', 'd'])
        """
        pass
    def union(self, *args, **kwargs): # real signature unknown
        """
         
        獲取兩個集合的並集,並生成一個新的集合;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.union(y)
        set(['a', 'c', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b'])
        """
        pass
    def update(self, *args, **kwargs): # real signature unknown
        """
         
        獲取兩個集合的並集,並生改變原集合;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.update(y)
        >>> x
        set(['a', 'c', 'b', 'd'])
        >>> y
        set(['c', 'd'])
        """
        pass
    def __and__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__and__(y) 等同於 x&y
         
        集合與操做,至關於獲取兩個集合相同值,即交集,並進行返回; 
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__and__(y)
        set(['c'])
        >>> x
        set(['a', 'c', 'b'])
        >>> y
        set(['c', 'd'])
        >>> x = set(['a','b','c'])
        >>> y = set(['b','c'])
        >>> x & y
        set(['c', 'b'])
        """
        pass
    def __cmp__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__cmp__(y) 等同於 cmp(x,y)

        無心義  (Python2特有,Python3已刪除)
        """
        pass
    def __contains__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__contains__(y) 等同於 y in x

        集合包含判斷,即判斷y是否包含在x中,返回布爾值;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = 'a'
        >>> x.__contains__(y)
        True
        >>> y in x
        True
        >>> y = 'd'
        >>> x.__contains__(y)
        False
        """
        pass
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__eq__(y) 等同於 x==y

        集合等同於判斷,即判斷x是否等於y,返回布爾值;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b','c'])
        >>> x.__eq__(y)
        True
        >>> x == y
        True
        >>> y = set(['a','b'])
        >>> x == y
        False 
        """
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ 
        x.__getattribute__('name') 等同於 x.name 
        """
        pass
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ge__(y) 等同於 x>=y

        集合大小等於判斷,返回布爾值; 
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.__ge__(y)
        True
        >>> x >= y
        True
        >>> y = set(['a','b','c'])
        >>> x >= y
        True
        >>> y = set(['a','b','c','d'])
        >>> x >= y
        False
        """
        pass
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__gt__(y) 等同於 x>y 

        集合大於判斷,返回布爾值;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['a','b'])
        >>> x.__gt__(y)
        True
        >>> x > y
        True
        >>> y = set(['a','b','c'])
        >>> x > y
        False
        """
        pass
    def __iand__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__iand__(y) 等同於 x&=y 

        集合與操做,至關於獲取兩個集合相同值,即交集,並進行返回及修改集合x; 
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__iand__(y)
        set(['c'])
        >>> x
        set(['c'])
        >>> y
        set(['c', 'd'])
        >>> x = set(['a','b','c'])
        """
        pass
    def __init__(self, seq=()): # known special case of set.__init__
        """
        set() -> new empty set object
        set(iterable) -> new set object
         
        Build an unordered collection of unique elements.
        # (copied from class doc)

        構造方法,執行x = set()時自動調用集合函數;
        """
        pass
    def __ior__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ior__(y) 等同於 x|=y 

        獲取兩個集合的並集,並進行返回及改變原集合;
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__ior__(y)
        set(['a', 'c', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b', 'd'])
        >>> y
        set(['c', 'd'])
        >>> x = set(['a','b','c'])
        >>> x |= y
        set(['a', 'c', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b', 'd'])
        >>> y
        set(['c', 'd'])        
        """
        pass
    def __isub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__isub__(y) 等同於 x-=y 

        集合減法,即x集合減去y集合,並進行結果返回及修改x集合;
        例如:
        >>> x = set(['a','b','c','d'])
        >>> y = set(['c','d'])
        >>> x.__isub__(y)
        set(['a', 'b'])
        >>> x
        set(['a', 'b'])
        >>> y
        set(['c', 'd'])
        """
        pass
    def __iter__(self): # real signature unknown; restored from __doc__
        """ 
        x.__iter__() 等同於 iter(x) 

        迭代對象,返回本身;
        """
        pass
    def __ixor__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ixor__(y) 等同於 x^=y 

        把兩個集合中的不一樣元素(對稱差集)放到一個原集合中,即把x與y集合的不一樣元素,放置到x集合中;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__ixor__(y)
        set(['a', 'b', 'd'])
        >>> x
        set(['a', 'b', 'd'])
        >>> y
        set(['c', 'd'])
        >>> x = set(['a','b','c'])
        >>> x ^= y
        set(['a', 'b', 'd'])
        >>> x
        set(['a', 'b', 'd'])
        >>> y
        set(['c', 'd'])
        """
        pass
    def __len__(self): # real signature unknown; restored from __doc__
        """ 
        x.__len__() 等同於 len(x) 

        返回集合長度;
        """
        pass
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__le__(y) 等同於 x<=y 

        集合小於判斷,返回布爾值;
        """
        pass
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__lt__(y) 等同於 x<y 

        集合小於判斷,返回布爾值;
        """
        pass
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ 
        T.__new__(S, ...) -> a new object with type S, a subtype of T 
        """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ne__(y) 等同於 x!=y 

        集合不等於判斷,返回布爾值;
        """
        pass
    def __or__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__or__(y) 等同於 x|y 

        獲取兩個集合的並集,並生成一個新的集合;
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__or__(y)
        set(['a', 'c', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b'])
        >>> y
        set(['c', 'd'])
        >>> y | x
        set(['a', 'c', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b'])
        >>> y
        set(['c', 'd'])
        """
        pass
    def __rand__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rand__(y) 等同於 y&x 

        獲取兩個集合的交集,生成一個新的集合;
        例如:
        >>> x = set(['a','b'])
        >>> y = set(['a','b','c'])
        >>> x.__rand__(y)
        set(['a', 'b'])
        >>> y & x
        set(['a', 'b'])
        """
        pass
    def __reduce__(self, *args, **kwargs): # real signature unknown
        """ 
        Return state information for pickling. 
        """
        pass
    def __repr__(self): # real signature unknown; restored from __doc__
        """ 
        x.__repr__() 等同於 repr(x) 

        轉化爲解釋器可讀取的形式,即轉換爲字符串格式;
        """
        pass
    def __ror__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__ror__(y) 等同於 y|x 

        獲取兩個集合的並集,並生成一個新的集合;;
        例如:
        >>> x = set(['a','b'])
        >>> y = set(['a','b','c'])
        >>> x.__ror__(y)
        set(['a', 'c', 'b'])
        >>> x
        set(['a', 'b'])
        >>> y
        set(['a', 'c', 'b'])
        >>> y | x
        set(['a', 'c', 'b'])
        """
        pass
    def __rsub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rsub__(y) 等同於 y-x 

        獲取兩個集合的不一樣(差集),並生成一個新的集合(項在y中,但不在x中);
        例如:
        >>> x = set(['a','b'])
        >>> y = set(['a','b','c'])
        >>> x.__rsub__(y)
        set(['c'])
        >>> y.__rsub__(x)
        set([])
        """
        pass
    def __rxor__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__rxor__(y) 等同於 y^x 

        獲取兩個集合的不一樣(差集),並生成一個新的集合
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__rxor__(y)
        set(['a', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b'])
        >>> y
        set(['c', 'd'])
        >>> y ^ x
        set(['a', 'b', 'd'])
        """
        pass
    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ 
        S.__sizeof__() -> size of S in memory, in bytes 
        返回內存中的大小(以字節爲單位);
        """
        pass
    def __sub__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__sub__(y) 等同於 x-y 

        獲取兩個集合的不一樣(差集),並生成一個新的集合(項在x中,但不在y中);
        例如:
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__sub__(y)
        set(['a', 'b'])
        >>> x
        set(['a', 'c', 'b'])
        >>> y
        set(['c', 'd'])
        >>> y - x
        set(['d'])
        """
        pass
    def __xor__(self, y): # real signature unknown; restored from __doc__
        """ 
        x.__xor__(y) 等同於 x^y 

        兩個集合不相同的元素(差集),並返回結果;
        >>> x = set(['a','b','c'])
        >>> y = set(['c','d'])
        >>> x.__xor__(y)
        set(['a', 'b', 'd'])
        >>> x
        set(['a', 'c', 'b'])
        >>> x
        set(['c', 'd'])
        >>> y ^ x
        set(['a', 'b', 'd'])
        """
        pass
    __hash__ = None
set

9、collection系列函數說明

collections模塊自Python 2.4版本開始被引入,包含了dict、set、list、tuple之外的一些特殊的容器類型,分別是:

OrderedDict類:排序字典,是字典的子類。引入自2.7;

namedtuple()函數:命名元組,是一個工廠函數。引入自2.6;

Counter類:爲hashable對象計數,是字典的子類。引入自2.7;

deque:雙向隊列。引入自2.4;

defaultdict:使用工廠函數建立字典,使不用考慮缺失的字典鍵。引入自2.5;

使用的時候須要用import導入collections模塊;

一、計數器(counter)函數說明

Counter類的目的是用來跟蹤值出現的次數。它是一個無序的容器類型,以字典的鍵值對形式存儲,其中元素做爲key,其計數做爲value。計數值能夠是任意的Interger(包括0和負數);

注:具有字典的全部功能 + 本身的功能;

########################################################################
###  Counter
########################################################################
def _count_elements(mapping, iterable):
    'Tally elements from the iterable.'
    mapping_get = mapping.get
    for elem in iterable:
        mapping[elem] = mapping_get(elem, 0) + 1
try:                                    # Load C helper function if available
    from _collections import _count_elements
except ImportError:
    pass
'''
若是C的幫助函數可用的話,則加載; (Python3新增)
'''
class Counter(dict):
    '''
    Dict子類用於計算哈希項,有時稱爲包或多集,元素存儲爲字典鍵,它們的計數存儲爲字典值;
    >>> c = Counter('abcdeabcdabcaba')  # count elements from a string
    >>> c.most_common(3)                # three most common elements
    [('a', 5), ('b', 4), ('c', 3)]
    >>> sorted(c)                       # list all unique elements
    ['a', 'b', 'c', 'd', 'e']
    >>> ''.join(sorted(c.elements()))   # list elements with repetitions
    'aaaaabbbbcccdde'
    >>> sum(c.values())                 # total of all counts
    15
    >>> c['a']                          # count of letter 'a'
    5
    >>> for elem in 'shazam':           # update counts from an iterable
    ...     c[elem] += 1                # by adding 1 to each element's count
    >>> c['a']                          # now there are seven 'a'
    7
    >>> del c['b']                      # remove all 'b'
    >>> c['b']                          # now there are zero 'b'
    0
    >>> d = Counter('simsalabim')       # make another counter
    >>> c.update(d)                     # add in the second counter
    >>> c['a']                          # now there are nine 'a'
    9
    >>> c.clear()                       # empty the counter
    >>> c
    Counter()
    Note:  If a count is set to zero or reduced to zero, it will remain
    in the counter until the entry is deleted or the counter is cleared:
    >>> c = Counter('aaabbc')
    >>> c['b'] -= 2                     # reduce the count of 'b' by two
    >>> c.most_common()                 # 'b' is still in, but its count is zero
    [('a', 3), ('c', 1), ('b', 0)]
    '''
    # References:
    #   http://en.wikipedia.org/wiki/Multiset
    #   http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html
    #   http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm
    #   http://code.activestate.com/recipes/259174/
    #   Knuth, TAOCP Vol. II section 4.6.3
    def __init__(*args, **kwds):
        '''
        建立一個新的空Counter對象,可對輸入可迭代元素進行計數,也能夠對另一個元素映射過來的元素進行計數;
        主要是先調用父類(dict)的初始化,而後使用update函數來更新參數;
        >>> c = Counter()                           # a new, empty counter
        >>> c = Counter('gallahad')                 # a new counter from an iterable
        >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
        >>> c = Counter(a=4, b=2)                   # a new counter from keyword args
        '''
        if not args:
            raise TypeError("descriptor '__init__' of 'Counter' object "
                            "needs an argument")
        self, *args = args
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        super(Counter, self).__init__()
        self.update(*args, **kwds)
    def __missing__(self, key):
        'The count of elements not in the Counter is zero.'
        # Needed so that self[missing_item] does not raise KeyError
        return 0
        '''
        對於不存在的元素,返回計數器爲0;
        總結一下就是dict自己沒有這個方法,可是若是當前類爲dict的子類的話;
        會在缺失的狀況下查看有沒有實現__missing__方法,若是有的話,就返回__miss__方法的值;
        因此Counter做爲dict的子類實現了__missing__方法,在缺失的時候返回0;
        這也就是爲何在Counter類中,若是找不到key,會返回0而不是產生一個KeyError;
        例如:
        >>> import collections
        >>> c = collections.Counter('abbcc')
        >>> c['a']
        2
        >>> c['b']
        2
        >>> c['d']
        0
        '''
    def most_common(self, n=None):
        '''List the n most common elements and their counts from the most
        common to the least.  If n is None, then list all element counts.
        >>> Counter('abcdeabcdabcaba').most_common(3)
        [('a', 5), ('b', 4), ('c', 3)]
        '''
        # Emulate Bag.sortedByCount from Smalltalk
        if n is None:
            return sorted(self.items(), key=_itemgetter(1), reverse=True)
        return _heapq.nlargest(n, self.items(), key=_itemgetter(1))
        '''
        數量從大到寫排列,返回一個TopN列表,若是n沒有被指定,則返回全部元素;
        當多個元素計數值相同時,按照字母序排列;
        例如:
        >>> Counter('abcdeabcdabcaba').most_common(3)
        [('a', 5), ('b', 4), ('c', 3)]
        '''
    def elements(self):
        '''Iterator over elements repeating each as many times as its count.
        >>> c = Counter('ABCABC')
        >>> sorted(c.elements())
        ['A', 'A', 'B', 'B', 'C', 'C']
        # Knuth's example for prime factors of 1836:  2**2 * 3**3 * 17**1
        >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
        >>> product = 1
        >>> for factor in prime_factors.elements():     # loop over factors
        ...     product *= factor                       # and multiply them
        >>> product
        1836
        Note, if an element's count has been set to zero or is a negative
        number, elements() will ignore it.
        '''
        # Emulate Bag.do from Smalltalk and Multiset.begin from C++.
        return _chain.from_iterable(_starmap(_repeat, self.items()))
        '''
        返回一個迭代器。元素被重複了多少次,在該迭代器中就包含多少個該元素;
        全部元素按照字母序排序,個數小於1的元素不被包含;
        注:此處非全部元素集合,而是包含全部元素集合的迭代器; 
        例如:
        >>> import collections
        >>> c = collections.Counter(a=4, b=2, c=0, d=-2)
        >>> list(c.elements())
        ['a', 'a', 'a', 'a', 'b', 'b']
        '''
    # Override dict methods where necessary
    @classmethod
    def fromkeys(cls, iterable, v=None):
        # There is no equivalent method for counters because setting v=1
        # means that no element can have a count greater than one.
        raise NotImplementedError(
            'Counter.fromkeys() is undefined.  Use Counter(iterable) instead.')
            '''
            未實現的類方法;
            '''
    def update(*args, **kwds):
        '''Like dict.update() but add counts instead of replacing them.
        Source can be an iterable, a dictionary, or another Counter instance.
        >>> c = Counter('which')
        >>> c.update('witch')           # add elements from another iterable
        >>> d = Counter('watch')
        >>> c.update(d)                 # add elements from another counter
        >>> c['h']                      # four 'h' in which, witch, and watch
        4
        '''
        # The regular dict.update() operation makes no sense here because the
        # replace behavior results in the some of original untouched counts
        # being mixed-in with all of the other counts for a mismash that
        # doesn't have a straight-forward interpretation in most counting
        # contexts.  Instead, we implement straight-addition.  Both the inputs
        # and outputs are allowed to contain zero and negative counts.
        if not args:
            raise TypeError("descriptor 'update' of 'Counter' object "
                            "needs an argument")
        self, *args = args
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        iterable = args[0] if args else None
        if iterable is not None:
            if isinstance(iterable, Mapping):
                if self:
                    self_get = self.get
                    for elem, count in iterable.items():
                        self[elem] = count + self_get(elem, 0)
                else:
                    super(Counter, self).update(iterable) # fast path when counter is empty
            else:
                _count_elements(self, iterable)
        if kwds:
            self.update(kwds)
        '''
        更新計數器,其實就是增長;若是原來沒有,則新建,若是有則加一;
        例如:
        >>> from collections import Counter
        >>> c = Counter('which')
        >>> c
        Counter({'h': 2, 'i': 1, 'c': 1, 'w': 1})
        >>> c.update('witch')
        >>> c
        Counter({'h': 3, 'i': 2, 'c': 2, 'w': 2, 't': 1})
        >>> c['h']
        3
        >>> d = Counter('watch')
        >>> d
        Counter({'a': 1, 'h': 1, 'c': 1, 't': 1, 'w': 1})
        >>> c.update(d)
        >>> c
        Counter({'h': 4, 'c': 3, 'w': 3, 'i': 2, 't': 2, 'a': 1})
        >>> c['h']
        4
        '''
    def subtract(*args, **kwds):
        '''Like dict.update() but subtracts counts instead of replacing them.
        Counts can be reduced below zero.  Both the inputs and outputs are
        allowed to contain zero and negative counts.
        Source can be an iterable, a dictionary, or another Counter instance.
        >>> c = Counter('which')
        >>> c.subtract('witch')             # subtract elements from another iterable
        >>> c.subtract(Counter('watch'))    # subtract elements from another counter
        >>> c['h']                          # 2 in which, minus 1 in witch, minus 1 in watch
        0
        >>> c['w']                          # 1 in which, minus 1 in witch, minus 1 in watch
        -1
        '''
        if not args:
            raise TypeError("descriptor 'subtract' of 'Counter' object "
                            "needs an argument")
        self, *args = args
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        iterable = args[0] if args else None
        if iterable is not None:
            self_get = self.get
            if isinstance(iterable, Mapping):
                for elem, count in iterable.items():
                    self[elem] = self_get(elem, 0) - count
            else:
                for elem in iterable:
                    self[elem] = self_get(elem, 0) - 1
        if kwds:
            self.subtract(kwds)
        '''
        相減,原來的計數器中的每個元素的數量減去後添加的元素的數量;
        例如:
        >>> from collections import Counter
        >>> c = Counter('which')
        >>> c.subtract('witch')
        >>> c
        Counter({'h': 1, 'i': 0, 'c': 0, 'w': 0, 't': -1})
        >>> c['h']
        1
        >>> d = Counter('watch')
        >>> c.subtract(d)
        >>> c['a']
        -1
        '''
    def copy(self):
        'Return a shallow copy.'
        return self.__class__(self)
        '''
        淺拷貝;
        例如:
        >>> from collections import Counter
        >>> c = Counter('abcdcba')
        >>> c
        Counter({'a': 2, 'c': 2, 'b': 2, 'd': 1})
        >>> d = c.copy()
        >>> d
        Counter({'a': 2, 'c': 2, 'b': 2, 'd': 1})
        '''
    def __reduce__(self):
        return self.__class__, (dict(self),)
        '''
        返回一個元組(類型,元組);
        例如:
        >>> c = Counter('abcdcba')
        >>> c.__reduce__()
        (<class 'collections.Counter'>, ({'a': 2, 'c': 2, 'b': 2, 'd': 1},))
        >>> d = c.__reduce__()
        >>> type(d)
        <type 'tuple'>
        '''
    def __delitem__(self, elem):
        'Like dict.__delitem__() but does not raise KeyError for missing values.'
        if elem in self:
            super().__delitem__(elem)
        '''
        刪除元素,等同於del;
        本質上就是一個不拋出KeyError的dict類的__delitem()__;
        >>> c = Counter('abcdcba')
        >>> c
        Counter({'a': 2, 'c': 2, 'b': 2, 'd': 1})
        >>> c['b'] = 0
        >>> c
        Counter({'a': 2, 'c': 2, 'd': 1, 'b': 0})
        >>> c.__delitem__('a')
        >>> c
        Counter({'c': 2, 'd': 1, 'b': 0})
        >>> del c['b']
        >>> c
        Counter({'c': 2, 'd': 1})
        '''
    def __repr__(self):
        if not self:
            return '%s()' % self.__class__.__name__
        try:
            items = ', '.join(map('%r: %r'.__mod__, self.most_common()))
            return '%s({%s})' % (self.__class__.__name__, items)
        except TypeError:
            # handle case where values are not orderable
            return '{0}({1!r})'.format(self.__class__.__name__, dict(self))
        '''
        若是沒有對象就返回類的名字,不然返回類的名字而且返回利用most_common()方法獲得類中的信息;
        例如:
        >>> from collections import Counter
        >>> c = Counter('aabbccdd')
        >>> c.__repr__()
        "Counter({'a': 2, 'c': 2, 'b': 2, 'd': 2})"
        >>> c = Counter()
        >>> c.__repr__()
        'Counter()'
        '''
    # Multiset-style mathematical operations discussed in:
    #       Knuth TAOCP Volume II section 4.6.3 exercise 19
    #       and at http://en.wikipedia.org/wiki/Multiset
    #
    # Outputs guaranteed to only include positive counts.
    #
    # To strip negative and zero counts, add-in an empty counter:
    #       c += Counter()
    def __add__(self, other):
        '''Add counts from two counters.
        >>> Counter('abbb') + Counter('bcc')
        Counter({'b': 4, 'c': 2, 'a': 1})
        '''
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        for elem, count in self.items():
            newcount = count + other[elem]
            if newcount > 0:
                result[elem] = newcount
        for elem, count in other.items():
            if elem not in self and count > 0:
                result[elem] = count
        return result
        '''
        加法運算,至關於+,結果中只會出現計數count大於0的元素;
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c2 = Counter({'b':2,'c':1})
        >>> c1.__add__(c2)
        Counter({'c': 4, 'b': 3})
        >>> c1 + c2
        Counter({'c': 4, 'b': 3})
        '''
    def __sub__(self, other):
        ''' Subtract count, but keep only results with positive counts.
        >>> Counter('abbbc') - Counter('bccd')
        Counter({'b': 2, 'a': 1})
        '''
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        for elem, count in self.items():
            newcount = count - other[elem]
            if newcount > 0:
                result[elem] = newcount
        for elem, count in other.items():
            if elem not in self and count < 0:
                result[elem] = 0 - count
        return result
        '''
        減法運算,至關於-,結果中只會出現計數count大於0的元素;
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c2 = Counter({'b':2,'c':1})
        >>> c1.__sub__(c2)
        Counter({'c': 2})
        >>> c1 - c2
        Counter({'c': 2})
        '''
    def __or__(self, other):
        '''Union is the maximum of value in either of the input counters.
        >>> Counter('abbb') | Counter('bcc')
        Counter({'b': 3, 'c': 2, 'a': 1})
        '''
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        for elem, count in self.items():
            other_count = other[elem]
            newcount = other_count if count < other_count else count
            if newcount > 0:
                result[elem] = newcount
        for elem, count in other.items():
            if elem not in self and count > 0:
                result[elem] = count
        return result
        '''
        並集運算,至關於|,結果中只會出現計數count大於0的元素及主要是選相同元素中count最大的一個;
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c2 = Counter({'b':2,'c':1})
        >>> c1.__or__(c2)
        Counter({'c': 3, 'b': 2})
        >>> c1 | c2
        Counter({'c': 3, 'b': 2})
        '''
    def __and__(self, other):
        ''' Intersection is the minimum of corresponding counts.
        >>> Counter('abbb') & Counter('bcc')
        Counter({'b': 1})
        '''
        if not isinstance(other, Counter):
            return NotImplemented
        result = Counter()
        for elem, count in self.items():
            other_count = other[elem]
            newcount = count if count < other_count else other_count
            if newcount > 0:
                result[elem] = newcount
        return result
        '''
        交集運算,至關於&,結果中只會出現計數count大於0的元素及主要是選相同元素中count最小的一個;
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c2 = Counter({'b':2,'c':1})
        >>> c1.__and__(c2)
        Counter({'c': 1, 'b': 1})
        >>> c1 & c2
        Counter({'c': 1, 'b': 1})
        '''
    def __pos__(self):
        'Adds an empty counter, effectively stripping negative and zero counts'
        result = Counter()
        for elem, count in self.items():
            if count > 0:
                result[elem] = count
        return result
        '''
        用於清除值爲負數和零的計數; (Python3新增)
        例如:
        >>> from collections import Counter
        >>> c1 = Counter({'a':0,'b':1,'c':-3})
        >>> c1.__pos__()
        Counter({'b': 1})
        '''
    def __neg__(self):
        '''Subtracts from an empty counter.  Strips positive and zero counts,
        and flips the sign on negative counts.
        '''
        result = Counter()
        for elem, count in self.items():
            if count < 0:
                result[elem] = 0 - count
        return result
        '''
        用於清除值爲正數或者零的計數,並將值爲負數的計數,轉換爲正數; (Python3新增)
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':-3})
        >>> c1.__neg__()
        Counter({'c': 3})
        '''
    def _keep_positive(self):
        '''Internal method to strip elements with a negative or zero count'''
        nonpositive = [elem for elem, count in self.items() if not count > 0]
        for elem in nonpositive:
            del self[elem]
        return self
    def __iadd__(self, other):
        '''Inplace add from another counter, keeping only positive counts.
        >>> c = Counter('abbb')
        >>> c += Counter('bcc')
        >>> c
        Counter({'b': 4, 'c': 2, 'a': 1})
        '''
        for elem, count in other.items():
            self[elem] += count
        return self._keep_positive()
        '''
        自加,至關於+=,結果中只會出現計數count大於0的元素; (Python3新增)
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c1 += Counter({'b':2,'c':1})
        >>> c1
        Counter({'c': 4, 'b': 3})
        '''
    def __isub__(self, other):
        '''Inplace subtract counter, but keep only results with positive counts.
        >>> c = Counter('abbbc')
        >>> c -= Counter('bccd')
        >>> c
        Counter({'b': 2, 'a': 1})
        '''
        for elem, count in other.items():
            self[elem] -= count
        return self._keep_positive()
        '''
        自減,至關於-=,結果中只會出現計數count大於0的元素; (Python3新增)
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c1 -= Counter({'b':1,'c':1})
        >>> c1
        Counter({'c': 2})
        '''
    def __ior__(self, other):
        '''Inplace union is the maximum of value from either counter.
        >>> c = Counter('abbb')
        >>> c |= Counter('bcc')
        >>> c
        Counter({'b': 3, 'c': 2, 'a': 1})
        '''
        for elem, other_count in other.items():
            count = self[elem]
            if other_count > count:
                self[elem] = other_count
        return self._keep_positive()
        '''
        自並集運算,至關於|=,結果中只會出現計數count大於0的元素及主要是選相同元素中count最大的一個; (Python3新增)
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c1 |= Counter({'b':1,'d':2})
        >>> c1
        Counter({'c': 3, 'd': 2, 'b': 1})
        '''
    def __iand__(self, other):
        '''Inplace intersection is the minimum of corresponding counts.
        >>> c = Counter('abbb')
        >>> c &= Counter('bcc')
        >>> c
        Counter({'b': 1})
        '''
        for elem, count in self.items():
            other_count = other[elem]
            if other_count < count:
                self[elem] = other_count
        return self._keep_positive()
        '''
        自交集運算,至關於&=,結果中只會出現計數count大於0的元素及主要是選相同元素中count最小的一個; (Python3新增)
        例如:
        >>> c1 = Counter({'a':0,'b':1,'c':3})
        >>> c1 &= Counter({'b':1,'d':2})
        >>> c1
        Counter({'b': 1})
        '''
Counter

二、有序字典(OrderdDict)函數說明

OrderdDict是對字典類型的補充,他記住了字典元素添加的順序;

################################################################################
### OrderedDict
################################################################################
class _OrderedDictKeysView(KeysView):
    def __reversed__(self):
        yield from reversed(self._mapping)
'''
用於被OrderedDict的keys方法調用; (Python3新增)
'''
class _OrderedDictItemsView(ItemsView):
    def __reversed__(self):
        for key in reversed(self._mapping):
            yield (key, self._mapping[key])
'''
用於被OrderedDict的items方法調用; (Python3新增)
'''
class _OrderedDictValuesView(ValuesView):
    def __reversed__(self):
        for key in reversed(self._mapping):
            yield self._mapping[key]
'''
用於被OrderedDict的values方法調用; (Python3新增)
'''
class _Link(object):
    __slots__ = 'prev', 'next', 'key', '__weakref__'
'''
未實現的方法; (Python3新增)
'''
class OrderedDict(dict):
    'Dictionary that remembers insertion order'
    # An inherited dict maps keys to values.
    # The inherited dict provides __getitem__, __len__, __contains__, and get.
    # The remaining methods are order-aware.
    # Big-O running times for all methods are the same as regular dictionaries.
    # The internal self.__map dict maps keys to links in a doubly linked list.
    # The circular doubly linked list starts and ends with a sentinel element.
    # The sentinel element never gets deleted (this simplifies the algorithm).
    # The sentinel is in self.__hardroot with a weakref proxy in self.__root.
    # The prev links are weakref proxies (to prevent circular references).
    # Individual links are kept alive by the hard reference in self.__map.
    # Those hard references disappear when a key is deleted from an OrderedDict.
    '''
    記住插入順序的字典;
    繼承的dict的keys和values;
    繼承的dict提供__getitem__,__len__,__contains__和get方法;
    其他的方法都按順序執行;
    全部方法的執行時間都和普通字典同樣;
    引用在OrderedDict刪除鍵時消失;
    '''
    def __init__(*args, **kwds):
        '''
        初始化有序字典。簽名與常規字典相同,但不推薦使用關鍵字參數,由於插入順序;
        '''
        if not args:
            raise TypeError("descriptor '__init__' of 'OrderedDict' object "
                            "needs an argument")
        self, *args = args
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        try:
            self.__root
        except AttributeError:
            self.__hardroot = _Link()
            self.__root = root = _proxy(self.__hardroot)
            root.prev = root.next = root
            self.__map = {}
        self.__update(*args, **kwds)
    def __setitem__(self, key, value,
                    dict_setitem=dict.__setitem__, proxy=_proxy, Link=_Link):
        'od.__setitem__(i, y) <==> od[i]=y'
        # Setting a new item creates a new link at the end of the linked list,
        # and the inherited dictionary is updated with the new key/value pair.
        if key not in self:
            self.__map[key] = link = Link()
            root = self.__root
            last = root.prev
            link.prev, link.next, link.key = last, root, key
            last.next = link
            root.prev = proxy(link)
        dict_setitem(self, key, value)
        '''
        od.__setitem__(i, y)等同於od[i]=y;
        設置的新項目會在連接列表的末尾建立一個新連接,而且繼承的字典使用新的鍵/值對進行更新方法;
        例如:
        >>> from collections import OrderedDict
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])
        >>> od.__setitem__('k4','v4')
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')])
        >>> od['k5'] = 'v5'
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4'), ('k5', 'v5')])
        '''
    def __delitem__(self, key, dict_delitem=dict.__delitem__):
        'od.__delitem__(y) <==> del od[y]'
        # Deleting an existing item uses self.__map to find the link which gets
        # removed by updating the links in the predecessor and successor nodes.
        dict_delitem(self, key)
        link = self.__map.pop(key)
        link_prev = link.prev
        link_next = link.next
        link_prev.next = link_next
        link_next.prev = link_prev
        link.prev = None
        link.next = None
        '''
        od.__delitem__(y)等同於del od[y];
        使用self.__map找到現有項目並進行刪除,刪除後經過更新前導節點和後繼節點的連接來覆蓋刪除的連接;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od.__delitem__('k1')
        >>> od
        OrderedDict([('k2', 'v2'), ('k3', 'v3')])
        >>> del od['k2']
        >>> od
        OrderedDict([('k3', 'v3')])
        '''
    def __iter__(self):
        'od.__iter__() <==> iter(od)'
        # Traverse the linked list in order.
        root = self.__root
        curr = root.next
        while curr is not root:
            yield curr.key
            curr = curr.next
        '''
        od.__iter__()等同於iter(od)
        按順序遍歷字典鏈表;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])
        >>> od.__iter__()
        <odict_iterator object at 0x0000027FF1D11F10>
        >>> nod = od.__iter__()
        >>> type(nod)
        <class 'odict_iterator'>
        >>> iter(od)
        <odict_iterator object at 0x0000027FF1D11F10>
        '''
    def __reversed__(self):
        'od.__reversed__() <==> reversed(od)'
        # Traverse the linked list in reverse order.
        root = self.__root
        curr = root.prev
        while curr is not root:
            yield curr.key
            curr = curr.prev
        '''
        od.__reversed__()等同於reversed(od)
        以相反的順序遍歷字典鏈表,及返回一個反向迭代器;       
        '''
    def clear(self):
        'od.clear() -> None.  Remove all items from od.'
        root = self.__root
        root.prev = root.next = root
        self.__map.clear()
        dict.clear(self)
        '''
        刪除全部項目;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])
        >>> od.clear()
        >>> od
        OrderedDict()
        '''
    def popitem(self, last=True):
        '''od.popitem() -> (k, v), return and remove a (key, value) pair.
        Pairs are returned in LIFO order if last is true or FIFO order if false.
        '''
        if not self:
            raise KeyError('dictionary is empty')
        root = self.__root
        if last:
            link = root.prev
            link_prev = link.prev
            link_prev.next = root
            root.prev = link_prev
        else:
            link = root.next
            link_next = link.next
            root.next = link_next
            link_next.prev = root
        key = link.key
        del self.__map[key]
        value = dict.pop(self, key)
        return key, value
        '''
        按照先進先出刪除key,value,並返回刪除key和value;
        若是參數last默認值True,表示以LIFO順序(先進先出)進行刪除和返回;
        若是last爲Flase,則以FIFO順序(後進先出)進行刪除和返回;
        也可直接指定key的索引值進行刪除;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.popitem()
        ('k4', 'v4')
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])
        >>> od.popitem(last = False)
        ('k1', 'v1')
        >>> od
        OrderedDict([('k2', 'v2'), ('k3', 'v3')])
        >>> od.popitem(0)
        ('k2', 'v2')
        >>> od
        OrderedDict([('k3', 'v3')])
        '''
    def move_to_end(self, key, last=True):
        '''Move an existing element to the end (or beginning if last==False).
        Raises KeyError if the element does not exist.
        When last=True, acts like a fast version of self[key]=self.pop(key).
        '''
        link = self.__map[key]
        link_prev = link.prev
        link_next = link.next
        link_prev.next = link_next
        link_next.prev = link_prev
        root = self.__root
        if last:
            last = root.prev
            link.prev = last
            link.next = root
            last.next = root.prev = link
        else:
            first = root.next
            link.prev = root
            link.next = first
            root.next = first.prev = link
        '''
        移動現有元素,等同於od[key] = od.pop(key); (Python3新增)
        當last參數爲True(默認值)時,將現有元素移動到結尾;
        若是last參數爲False時,則將現有元素移動開頭;
        若是元素不存在,則引起KetError;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.move_to_end('k1')
        >>> od
        OrderedDict([('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4'), ('k1', 'v1')])
        >>> od.move_to_end('k4',last = False)
        >>> od
        OrderedDict([('k4', 'v4'), ('k2', 'v2'), ('k3', 'v3'), ('k1', 'v1')])
        >>> od['k2'] = od.pop('k2')
        >>> od
        OrderedDict([('k4', 'v4'), ('k3', 'v3'), ('k1', 'v1'), ('k2', 'v2')])
        '''
    def __sizeof__(self):
        sizeof = _sys.getsizeof
        n = len(self) + 1                       # number of links including root
        size = sizeof(self.__dict__)            # instance dictionary
        size += sizeof(self.__map) * 2          # internal dict and inherited dict
        size += sizeof(self.__hardroot) * n     # link objects
        size += sizeof(self.__root) * n         # proxy objects
        return size
        '''
        返回內存中的大小(以字節爲單位); (Python3新增)
        '''
    update = __update = MutableMapping.update
    def keys(self):
        "D.keys() -> a set-like object providing a view on D's keys"
        return _OrderedDictKeysView(self)
        '''
        返回一個包含key的相似集合的對象;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.keys()
        odict_keys(['k1', 'k2', 'k3', 'k4'])
        '''
    def items(self):
        "D.items() -> a set-like object providing a view on D's items"
        return _OrderedDictItemsView(self)
        '''
        返回一個包含全部(key, value)相似集合的對象;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.items()
        odict_items([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')])
        '''
    def values(self):
        "D.values() -> an object providing a view on D's values"
        return _OrderedDictValuesView(self)
        '''
        返回一個包含value的相似集合的對象;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.values()
        odict_values(['v1', 'v2', 'v3', 'v4'])
        '''
    def iterkeys(self):
        'od.iterkeys() -> an iterator over the keys in od'
        return iter(self)
        '''
        key可迭代; (Python2特有,Python3已刪除)
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.iterkeys()
        <generator object __iter__ at 0x02E653A0>
        >>> nod = od.iterkeys()
        >>> type(nod)
        <type 'generator'>
        >>> nod.next()
        'k3'
        >>> nod.next()
        'k2'
        >>> nod.next()
        'k1'
        '''
    def itervalues(self):
        'od.itervalues -> an iterator over the values in od'
        for k in self:
            yield self[k]
        '''
        value可迭代; (Python2特有,Python3已刪除)
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>>od.itervalues()
        <generator object itervalues at 0x02E654E0>
        >>> nod = od.itervalues()
        >>> type(nod)
        <type 'generator'>
        >>> nod.next()
        'v3'
        >>> nod.next()
        'v2'
        >>> nod.next()
        'v1'
        '''
    def iteritems(self):
        'od.iteritems -> an iterator over the (key, value) pairs in od'
        for k in self:
            yield (k, self[k])
        '''
        key, value可迭代; (Python2特有,Python3已刪除)
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3','k4':'v4'})
        >>> od.iteritems()
        <generator object iteritems at 0x02E654E0>
        >>> nod = od.iteritems()
        >>> nod.next()
        ('k3', 'v3')
        >>> nod.next()
        ('k2', 'v2')
        >>> nod.next()
        ('k1', 'v1')
        '''
    __ne__ = MutableMapping.__ne__
    __marker = object()
    def pop(self, key, default=__marker):
        '''od.pop(k[,d]) -> v, remove specified key and return the corresponding
        value.  If key is not found, d is returned if given, otherwise KeyError
        is raised.
        '''
        if key in self:
            result = self[key]
            del self[key]
            return result
        if default is self.__marker:
            raise KeyError(key)
        return default
        '''
        刪除指定的鍵並返回相應的值,若是設置了d參數,並未找到key時,則返回d參數,不然返回KeyError;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od.pop('k1')
        'v1'
        >>> od
        OrderedDict([('k2', 'v2'), ('k3', 'v3')])
        >>> od.pop('k4')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        KeyError: 'k4'
        >>> od.pop('k4','k4_no_found')
        'k4_no_found'
        '''
    def setdefault(self, key, default=None):
        'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
        if key in self:
            return self[key]
        self[key] = default
        return default
        '''
        設置key鍵,若是已存在key鍵,則不改變key鍵,並返回原有key鍵的value值,若是不存在Key鍵,由爲它賦值;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od.setdefault('k3','v4')
        'v3'
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])
        >>> od.setdefault('k4','v4')
        'v4'
        >>> od
        OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')])
        '''
    @_recursive_repr()
    def __repr__(self):
        'od.__repr__() <==> repr(od)'
        if not self:
            return '%s()' % (self.__class__.__name__,)
        return '%s(%r)' % (self.__class__.__name__, list(self.items()))
        '''
        od.__repr__()等同於repr(od)
        轉化爲解釋器可讀取的形式,即轉換爲字符串格式;
        例如:
        >>> od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> nod = od.__repr__()
        >>> nod
        "OrderedDict([('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3')])"
        >>> type(nod)
        <class 'str'>
        '''
    def __reduce__(self):
        'Return state information for pickling'
        inst_dict = vars(self).copy()
        for k in vars(OrderedDict()):
            inst_dict.pop(k, None)
        return self.__class__, (), inst_dict or None, None, iter(self.items())
        '''
        返回pickling狀態的信息;
        例如:
        od = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> nod = od.__reduce__()
        >>> nod
        (<class 'collections.OrderedDict'>, (), None, None, <odict_iterator object at 0x0000027FF1D11F10>)
        >>> type(nod)
        <class 'tuple'>
        '''
    def copy(self):
        'od.copy() -> a shallow copy of od'
        return self.__class__(self)
        '''
        淺拷貝;
        '''
    @classmethod
    def fromkeys(cls, iterable, value=None):
        '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
        If not specified, the value defaults to None.
        '''
        self = cls()
        for key in iterable:
            self[key] = value
        return self
        '''
        獲取S的keys,並生成新字典 若是v參數未指定,則值默認爲None;
        例如:
        >>> od1 = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od2 = OrderedDict({'k4':'v4','k5':'v5','k6':'v6'})
        >>> od2.fromkeys(od1,'v')
        OrderedDict([('k1', 'v'), ('k2', 'v'), ('k3', 'v')])
        >>> od2
        OrderedDict([('k4', 'v4'), ('k5', 'v5'), ('k6', 'v6')])
        >>> od2.fromkeys(od1)
        OrderedDict([('k1', None), ('k2', None), ('k3', None)])
        '''
    def __eq__(self, other):
        '''od.__eq__(y) <==> od==y.  Comparison to another OD is order-sensitive
        while comparison to a regular mapping is order-insensitive.
        '''
        if isinstance(other, OrderedDict):
            return dict.__eq__(self, other) and all(map(_eq, self, other))
        return dict.__eq__(self, other)
        '''
        od.__eq__(y) 等同於 od==y        
        有序字典等同於判斷,即判斷od是否等於y,返回布爾值;
        例如:
        >>> od1 = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od2 = OrderedDict({'k4':'v4','k5':'v5','k6':'v6'})
        >>> od1.__eq__(od2)
        False
        >>> od2 = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od1.__eq__(od2)
        True
        >>> od1 == od2
        True
        '''
    def __ne__(self, other):
        'od.__ne__(y) <==> od!=y'
        return not self == other
        '''
        有序字典等不一樣於判斷,即判斷od是否不等於y,返回布爾值;
        例如:
        >>> od1 = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od2 = OrderedDict({'k4':'v4','k5':'v5','k6':'v6'})
        >>> od1.__ne__(od2)
        True
        >>> od1 != od2
        True
        >>> od2 = OrderedDict({'k1':'v1','k2':'v2','k3':'v3'})
        >>> od1.__ne__(od2)
        False
        '''
    # -- the following methods support python 3.x style dictionary views --
    def viewkeys(self):
        "od.viewkeys() -> a set-like object providing a view on od's keys"
        return KeysView(self)
        '''
        返回一個包含key的相似集合的對象; (Python2特有,Python3已刪除)
        '''
    def viewvalues(self):
        "od.viewvalues() -> an object providing a view on od's values"
        return ValuesView(self)
        '''
        返回一個包含value的相似集合的對象; (Python2特有,Python3已刪除)
        '''
    def viewitems(self):
        "od.viewitems() -> a set-like object providing a view on od's items"
        return ItemsView(self)
        '''
        返回一個包含全部(key, value)相似集合的對象; (Python2特有,Python3已刪除)
        '''
OrderedDict

三、默認字典(defaultdict)函數說明

defaultdict是對字典的類型的補充,他默認給字典的值設置了一個類型; 

class defaultdict(dict):
    """
    defaultdict(default_factory[, ...]) --> dict with default factory
     
    The default factory is called without arguments to produce
    a new value when a key is not present, in __getitem__ only.
    A defaultdict compares equal to a dict with the same items.
    All remaining arguments are treated the same as if they were
    passed to the dict constructor, including keyword arguments.
    """
    '''
    當不存在鍵時,僅在__getitem__調用中,默認字典能夠不帶參數以生成新值;
    默認字典與普通字典基本相同;
    全部參數都都與dict字典相同(包括關鍵字參數),執行時均被傳遞給dict的構造函數;
    '''
    def copy(self): # real signature unknown; restored from __doc__
        """ D.copy() -> a shallow copy of D. """
        pass
        '''
        淺拷貝;
        例如:
        >>> from collections import defaultdict
        >>> dd1 = defaultdict(list)
        >>> dd1['k1']
        []
        >>> dd1
        defaultdict(<class 'list'>, {'k1': []})
        >>> dd2 = dd1.copy()
        >>> dd2
        defaultdict(<class 'list'>, {'k1': []})
        '''
    def __copy__(self, *args, **kwargs): # real signature unknown
        """ D.copy() -> a shallow copy of D. """
        '''
        淺拷貝,等同於D.copy();
        '''
        pass
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass
    def __init__(self, default_factory=None, **kwargs): # known case of _collections.defaultdict.__init__
        """
        defaultdict(default_factory[, ...]) --> dict with default factory
         
        The default factory is called without arguments to produce
        a new value when a key is not present, in __getitem__ only.
        A defaultdict compares equal to a dict with the same items.
        All remaining arguments are treated the same as if they were
        passed to the dict constructor, including keyword arguments.
         
        # (copied from class doc)
        """
        pass
        '''
        構造方法;
        '''
    def __missing__(self, key): # real signature unknown; restored from __doc__
        """
        __missing__(key) # Called by __getitem__ for missing key; pseudo-code:
          if self.default_factory is None: raise KeyError((key,))
          self[key] = value = self.default_factory()
          return value
        """
        pass
    def __reduce__(self, *args, **kwargs): # real signature unknown
        """ Return state information for pickling. """
        pass
        '''
        返回pickling狀態的信息;
        '''
    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass
        '''
        x.__repr__()等同於repr(x)
        轉化爲解釋器可讀取的形式,即轉換爲字符串格式;
        '''
    default_factory = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
defaultdict

四、可命名元組(namedtuple)函數說明

根據nametuple能夠建立一個包含tuple全部功能以及其餘功能的類型;

################################################################################
### namedtuple
################################################################################
_class_template = """\
from builtins import property as _property, tuple as _tuple
from operator import itemgetter as _itemgetter
from collections import OrderedDict
class {typename}(tuple):
    '{typename}({arg_list})'
    __slots__ = ()
    _fields = {field_names!r}
    def __new__(_cls, {arg_list}):
        'Create new instance of {typename}({arg_list})'
        return _tuple.__new__(_cls, ({arg_list}))
    @classmethod
    def _make(cls, iterable, new=tuple.__new__, len=len):
        'Make a new {typename} object from a sequence or iterable'
        result = new(cls, iterable)
        if len(result) != {num_fields:d}:
            raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result))
        return result
    def _replace(_self, **kwds):
        'Return a new {typename} object replacing specified fields with new values'
        result = _self._make(map(kwds.pop, {field_names!r}, _self))
        if kwds:
            raise ValueError('Got unexpected field names: %r' % list(kwds))
        return result
    def __repr__(self):
        'Return a nicely formatted representation string'
        return self.__class__.__name__ + '({repr_fmt})' % self
    def _asdict(self):
        'Return a new OrderedDict which maps field names to their values.'
        return OrderedDict(zip(self._fields, self))
    def __getnewargs__(self):
        'Return self as a plain tuple.  Used by copy and pickle.'
        return tuple(self)
{field_defs}
"""
_repr_template = '{name}=%r'
_field_template = '''\
    {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}')
'''
def namedtuple(typename, field_names, *, verbose=False, rename=False, module=None):
    """Returns a new subclass of tuple with named fields.
    >>> Point = namedtuple('Point', ['x', 'y'])
    >>> Point.__doc__                   # docstring for the new class
    'Point(x, y)'
    >>> p = Point(11, y=22)             # instantiate with positional args or keywords
    >>> p[0] + p[1]                     # indexable like a plain tuple
    33
    >>> x, y = p                        # unpack like a regular tuple
    >>> x, y
    (11, 22)
    >>> p.x + p.y                       # fields also accessible by name
    33
    >>> d = p._asdict()                 # convert to a dictionary
    >>> d['x']
    11
    >>> Point(**d)                      # convert from a dictionary
    Point(x=11, y=22)
    >>> p._replace(x=100)               # _replace() is like str.replace() but targets named fields
    Point(x=100, y=22)
    """
    '''
    返回具備命名字段的元組的新子類;
    '''
    # Validate the field names.  At the user's option, either generate an error
    # message or automatically replace the field name with a valid name.
    if isinstance(field_names, str):
        field_names = field_names.replace(',', ' ').split()
    field_names = list(map(str, field_names))
    typename = str(typename)
    if rename:
        seen = set()
        for index, name in enumerate(field_names):
            if (not name.isidentifier()
                or _iskeyword(name)
                or name.startswith('_')
                or name in seen):
                field_names[index] = '_%d' % index
            seen.add(name)
    for name in [typename] + field_names:
        if type(name) is not str:
            raise TypeError('Type names and field names must be strings')
        if not name.isidentifier():
            raise ValueError('Type names and field names must be valid '
                             'identifiers: %r' % name)
        if _iskeyword(name):
            raise ValueError('Type names and field names cannot be a '
                             'keyword: %r' % name)
    seen = set()
    for name in field_names:
        if name.startswith('_') and not rename:
            raise ValueError('Field names cannot start with an underscore: '
                             '%r' % name)
        if name in seen:
            raise ValueError('Encountered duplicate field name: %r' % name)
        seen.add(name)
    # Fill-in the class template
    class_definition = _class_template.format(
        typename = typename,
        field_names = tuple(field_names),
        num_fields = len(field_names),
        arg_list = repr(tuple(field_names)).replace("'", "")[1:-1],
        repr_fmt = ', '.join(_repr_template.format(name=name)
                             for name in field_names),
        field_defs = '\n'.join(_field_template.format(index=index, name=name)
                               for index, name in enumerate(field_names))
    )
    # Execute the template string in a temporary namespace and support
    # tracing utilities by setting a value for frame.f_globals['__name__']
    namespace = dict(__name__='namedtuple_%s' % typename)
    exec(class_definition, namespace)
    result = namespace[typename]
    result._source = class_definition
    if verbose:
        print(result._source)
    # For pickling to work, the __module__ variable needs to be set to the frame
    # where the named tuple is created.  Bypass this step in environments where
    # sys._getframe is not defined (Jython for example) or sys._getframe is not
    # defined for arguments greater than 0 (IronPython), or where the user has
    # specified a particular module.
    if module is None:
        try:
            module = _sys._getframe(1).f_globals.get('__name__', '__main__')
        except (AttributeError, ValueError):
            pass
    if module is not None:
        result.__module__ = module
    return result
namedtuple

五、雙向隊列(deque)函數說明

一個線程安全的雙向隊列,可進可出,能夠從兩端添加和刪除元素;

class deque(object):
    """
    deque([iterable[, maxlen]]) --> deque object
     
    Build an ordered collection with optimized access from its endpoints.
     
    提供了兩端均可以操做的序列,這意味着,能夠在序列先後都執行添加或刪除;
    """
    def append(self, *args, **kwargs): # real signature unknown
        """ Add an element to the right side of the deque. """
        pass
        '''
        在deque的右邊添加一個元素;
        例如:
        >>> from collections import deque
        >>> d = deque()
        >>> d
        deque([])
        >>> d.append('a')
        >>> d
        deque(['a'])
        >>> d.append('b')
        >>> d
        deque(['a', 'b'])
        >>> d.append(['b','c'])
        >>> d
        deque(['a', 'a', ['b', 'c']])
        >>> d.append('b','c')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: append() takes exactly one argument (2 given)
        '''
    def appendleft(self, *args, **kwargs): # real signature unknown
        """ Add an element to the left side of the deque. """
        pass
        '''
        在deque的左邊添加一個元素;
        例如:
        >>> d = deque('a')
        >>> d
        deque(['a'])
        >>> d.appendleft('b')
        >>> d
        deque(['b', 'a'])
        '''
    def clear(self, *args, **kwargs): # real signature unknown
        """ Remove all elements from the deque. """
        pass
        '''
        從deque中刪除全部元素;
        例如:
        >>> d = deque(['a','b'])
        >>> d
        deque(['a', 'b'])
        >>> d.clear()
        >>> d
        deque([])
        '''
    def count(self, value): # real signature unknown; restored from __doc__
        """ D.count(value) -> integer -- return number of occurrences of value """
        return 0
        '''
        返回值的出現次數;
        例如:
        >>> d = deque(['a','a'])
        >>> d.count('a')
        2
        '''
    def extend(self, *args, **kwargs): # real signature unknown
        """ Extend the right side of the deque with elements from the iterable """
        pass
        '''
        使用可迭代的元素擴展deque的右側,即一次性可添加多個元素;
        例如:
        >>> d = deque(['a','b'])
        >>> d
        deque(['a', 'b'])        
        >>> d.extend(['c','d','e'])
        >>> d
        deque(['a', 'b', 'c', 'd', 'e'])
        '''
    def extendleft(self, *args, **kwargs): # real signature unknown
        """ Extend the left side of the deque with elements from the iterable """
        pass
        '''
        使用可迭代的元素擴展deque的左側,即一次性可添加多個元素;
        例如:
        >>> d = deque(['a','b'])
        >>> d
        deque(['a', 'b'])
        >>> d.extendleft(['c','d','e'])
        >>> d
        deque(['e', 'd', 'c', 'a', 'b'])
        '''
    def pop(self, *args, **kwargs): # real signature unknown
        """ Remove and return the rightmost element. """
        pass
        '''
        刪除並返回最右側的元素;
        例如:
        >>> d = deque(['a','b','c','d','e'])
        >>> d.pop()
        'e'
        '''
    def popleft(self, *args, **kwargs): # real signature unknown
        """ Remove and return the leftmost element. """
        pass
        '''
        刪除並返回最左側的元素;
        例如:
        >>> d = deque(['a','b','c','d','e'])
        >>> d.popleft()
        'a'
        '''
    def remove(self, value): # real signature unknown; restored from __doc__
        """ D.remove(value) -- remove first occurrence of value. """
        pass
        '''
        刪除指定的一個值;
        例如:
        >>> d = deque(['a','b','c','d','e'])
        >>> d.remove()
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: remove() takes exactly one argument (0 given)
        >>> d.remove('a')
        >>> d
        deque(['b', 'c', 'd', 'e'])
        >>> d.remove('c')
        >>> d
        deque(['b', 'd', 'e'])
        >>> d.remove('b','d')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: remove() takes exactly one argument (2 given)
        '''
    def reverse(self): # real signature unknown; restored from __doc__
        """ D.reverse() -- reverse *IN PLACE* """
        pass
        '''
        將元素反轉;
        例如:
        >>> d = deque(['a','b','c','d','e'])
        >>> d.reverse()
        >>> d
        deque(['e', 'd', 'c', 'b', 'a'])
        '''
    def rotate(self, *args, **kwargs): # real signature unknown
        """ Rotate the deque n steps to the right (default n=1).  If n is negative, rotates left. """
        pass
        '''
        將最後的n個元素向右反轉(默認n = 1),若是n爲負,則將最前的n個元素向左反轉;
        例如:
        >>> d = deque(['a','b','c','d','e'])
        >>> d.rotate()
        >>> d
        deque(['e', 'a', 'b', 'c', 'd'])
        >>> d.rotate(2)
        >>> d
        deque(['c', 'd', 'e', 'a', 'b'])
        >>> d.rotate(-4)
        >>> d
        deque(['b', 'c', 'd', 'e', 'a'])
        '''
    def __copy__(self, *args, **kwargs): # real signature unknown
        """ Return a shallow copy of a deque. """
        pass
        '''
        淺拷貝;
        '''
    def __delitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__delitem__(y) <==> del x[y] """
        pass
        '''
        刪除元素,等同於del;
        例如:
        >>> d = deque(['a','b','c','d','e'])
        >>> d.__delitem__(1)
        >>> d
        deque(['a', 'c', 'd', 'e'])
        >>> del d[2]
        >>> d
        deque(['a', 'c', 'e'])
        '''
    def __eq__(self, y): # real signature unknown; restored from __doc__
        """ x.__eq__(y) <==> x==y """
        pass
        '''
        等同於判斷,返回布爾值;
        例如:
        >>> x = deque(['a','b','c','d','e'])
        >>> y = deque(['a','b','c','d'])
        >>> x.__eq__(y)
        False
        >>> x == y
        False
        >>> y = deque(['a','b','c','d','e'])
        >>> x == y
        True
        '''
    def __getattribute__(self, name): # real signature unknown; restored from __doc__
        """ x.__getattribute__('name') <==> x.name """
        pass
    def __getitem__(self, y): # real signature unknown; restored from __doc__
        """ x.__getitem__(y) <==> x[y] """
        pass
        '''
        返回隊列指定下標的值,下標值需指定併爲整數型,不然報錯;
        例如:
        >>> x = deque(['a','b','c','d','e'])
        >>> x.__getitem__(2)
        'c'
        >>> x[3]
        'd'
        '''
    def __ge__(self, y): # real signature unknown; restored from __doc__
        """ x.__ge__(y) <==> x>=y """
        pass
        '''
        大於等於判斷,返回布爾值;
        例如:
        >>> x = deque(['a','b','c','d','e'])
        >>> y = deque(['a','b','c','d'])
        >>> x.__ge__(y)
        True
        >>> x >= y
        True
        '''
    def __gt__(self, y): # real signature unknown; restored from __doc__
        """ x.__gt__(y) <==> x>y """
        pass
        '''
        大於判斷,返回布爾值;
        '''
    def __iadd__(self, y): # real signature unknown; restored from __doc__
        """ x.__iadd__(y) <==> x+=y """
        pass
        '''
        自加,至關於+=;
        '''
    def __init__(self, iterable=(), maxlen=None): # known case of _collections.deque.__init__
        """
        deque([iterable[, maxlen]]) --> deque object
         
        Build an ordered collection with optimized access from its endpoints.
        # (copied from class doc)
        """
        pass
        '''
        構造方法,執行x = deque()時自動調用deque函數;
        '''
    def __iter__(self): # real signature unknown; restored from __doc__
        """ x.__iter__() <==> iter(x) """
        pass
        '''
        在deque上返回一個迭代器;
        '''
    def __len__(self): # real signature unknown; restored from __doc__
        """ x.__len__() <==> len(x) """
        pass
        '''
        返回隊列長度;
        例如:
        >>> x = deque(['a','b','c','d','e'])
        >>> x.__len__()
        5
        >>> len(x)
        5
        '''
    def __le__(self, y): # real signature unknown; restored from __doc__
        """ x.__le__(y) <==> x<=y """
        pass
        '''
        小於等於判斷,返回布爾值;
        '''
    def __lt__(self, y): # real signature unknown; restored from __doc__
        """ x.__lt__(y) <==> x<y """
        pass
        '''
        小於判斷,返回布爾值;
        '''
    @staticmethod # known case of __new__
    def __new__(S, *more): # real signature unknown; restored from __doc__
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass
    def __ne__(self, y): # real signature unknown; restored from __doc__
        """ x.__ne__(y) <==> x!=y """
        pass
        '''
        不等於判斷,返回布爾值;
        '''
    def __reduce__(self, *args, **kwargs): # real signature unknown
        """ Return state information for pickling. """
        pass
        '''
        返回pickling的狀態信息;
        '''
    def __repr__(self): # real signature unknown; restored from __doc__
        """ x.__repr__() <==> repr(x) """
        pass
        '''
        轉化爲解釋器可讀取的形式,即轉換爲字符串格式;
        '''
    def __reversed__(self): # real signature unknown; restored from __doc__
        """ D.__reversed__() -- return a reverse iterator over the deque """
        pass
        '''
        在deque上返回一個反向迭代器;
        '''
    def __setitem__(self, i, y): # real signature unknown; restored from __doc__
        """ x.__setitem__(i, y) <==> x[i]=y """
        pass
        '''
        對隊列裏,指定的下標值進行修改,i需爲整數,而且不能超過隊列的下標範圍;
        例如:
        >>> x = deque(['a','b','c','d','e'])
        >>> x.__setitem__(2,'f')
        >>> x
        deque(['a', 'b', 'f', 'd', 'e'])
        >>> x[4] = 'g'
        >>> x
        deque(['a', 'b', 'f', 'd', 'g'])
        >>> x[5] = 'h'
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        IndexError: deque index out of range
        '''
    def __sizeof__(self): # real signature unknown; restored from __doc__
        """ D.__sizeof__() -- size of D in memory, in bytes """
        pass
        '''
        獲取內存中隊列的大小,以字節爲單位;
        '''
    maxlen = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """maximum size of a deque or None if unbounded"""
    __hash__ = None
deque

六、單向隊列(Queue)函數說明

Queue是python標準庫中的線程安全的隊列FIFO(先進先出)實現,提供了一個適用於多線程編程的先進先出的數據結構,即隊列,用來在生產者和消費者線程之間的信息傳遞;

Python2中使用Queue的方法是,from Queue import Queue;

而Python3中使用Queue的方法是,from queue import Queue;

class Queue:
    '''Create a queue object with a given maximum size.
    If maxsize is <= 0, the queue size is infinite.
    '''
    '''
    Queue提供了一個基本的FIFO容器,使用方法很簡單,maxsize是個整數,指明瞭隊列中能存放的數據個數的上限。一旦達到上限,插入會致使阻塞,直到隊列中的數據被消費掉。若是maxsize小於或者等於0,隊列大小沒有限制。
    '''
    def __init__(self, maxsize=0):
        self.maxsize = maxsize
        self._init(maxsize)
        # mutex must be held whenever the queue is mutating.  All methods
        # that acquire mutex must release it before returning.  mutex
        # is shared between the three conditions, so acquiring and
        # releasing the conditions also acquires and releases mutex.
        self.mutex = threading.Lock()
        # Notify not_empty whenever an item is added to the queue; a
        # thread waiting to get is notified then.
        self.not_empty = threading.Condition(self.mutex)
        # Notify not_full whenever an item is removed from the queue;
        # a thread waiting to put is notified then.
        self.not_full = threading.Condition(self.mutex)
        # Notify all_tasks_done whenever the number of unfinished tasks
        # drops to zero; thread waiting to join() is notified to resume
        self.all_tasks_done = threading.Condition(self.mutex)
        self.unfinished_tasks = 0
        '''
        構造函數,執行x = queue()時自動調用Queue函數;
        '''
    def task_done(self):
        '''Indicate that a formerly enqueued task is complete.
        Used by Queue consumer threads.  For each get() used to fetch a task,
        a subsequent call to task_done() tells the queue that the processing
        on the task is complete.
        If a join() is currently blocking, it will resume when all items
        have been processed (meaning that a task_done() call was received
        for every item that had been put() into the queue).
        Raises a ValueError if called more times than there were items
        placed in the queue.
        '''
        with self.all_tasks_done:
            unfinished = self.unfinished_tasks - 1
            if unfinished <= 0:
                if unfinished < 0:
                    raise ValueError('task_done() called too many times')
                self.all_tasks_done.notify_all()
            self.unfinished_tasks = unfinished
        '''
        意味着以前入隊的一個任務已經完成;
        由隊列的消費者線程調用。每個get()調用獲得一個任務,接下來的task_done()調用告訴隊列該任務已經處理完畢。
        若是當前一個join()正在阻塞,它將在隊列中的全部任務都處理完時恢復執行(即每個由put()調用入隊的任務都有一個對應的task_done()調用)。
        若是調用的次數比在隊列中放置的項目多,則引起ValueError;
        '''
    def join(self):
        '''Blocks until all items in the Queue have been gotten and processed.
        The count of unfinished tasks goes up whenever an item is added to the
        queue. The count goes down whenever a consumer thread calls task_done()
        to indicate the item was retrieved and all work on it is complete.
        When the count of unfinished tasks drops to zero, join() unblocks.
        '''
        with self.all_tasks_done:
            while self.unfinished_tasks:
                self.all_tasks_done.wait()
        '''
        阻塞調用線程,直到隊列中的全部任務被處理掉;
        只要有數據被加入隊列,未完成的任務數就會增長;
        當消費者線程調用task_done()(意味着有消費者取得任務並完成任務),未完成的任務數就會減小;
        當未完成的任務數降到0,join()解除阻塞;
        '''
    def qsize(self):
        '''Return the approximate size of the queue (not reliable!).'''
        with self.mutex:
            return self._qsize()
        '''
        返回隊列的大體大小(不可靠!)
        '''
    def empty(self):
        '''Return True if the queue is empty, False otherwise (not reliable!).
        This method is likely to be removed at some point.  Use qsize() == 0
        as a direct substitute, but be aware that either approach risks a race
        condition where a queue can grow before the result of empty() or
        qsize() can be used.
        To create code that needs to wait for all queued tasks to be
        completed, the preferred technique is to use the join() method.
        '''
        with self.mutex:
            return not self._qsize()
        '''
        若是隊列爲空,返回True,不然返回False(不可靠!);
        這種方法極可能在某個時候被刪除。並由qsize() == 0來替代,可是要注意,無論是使用empty()仍是qsize(),都有可能會在隊列產生風險;
        要建立須要等待全部排隊任務完成的代碼,首選的技術是使用join()方法;
        '''
    def full(self):
        '''Return True if the queue is full, False otherwise (not reliable!).
        This method is likely to be removed at some point.  Use qsize() >= n
        as a direct substitute, but be aware that either approach risks a race
        condition where a queue can shrink before the result of full() or
        qsize() can be used.
        '''
        with self.mutex:
            return 0 < self.maxsize <= self._qsize()
        '''
        若是隊列已滿,返回True,不然返回False(不可靠!);
        這種方法極可能在某個時候被刪除。並由qsize() >= n來替代,可是要注意,無論是使用full()仍是qsize(),都有可能會在隊列產生風險;
        '''
    def put(self, item, block=True, timeout=None):
        '''Put an item into the queue.
        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until a free slot is available. If 'timeout' is
        a non-negative number, it blocks at most 'timeout' seconds and raises
        the Full exception if no free slot was available within that time.
        Otherwise ('block' is false), put an item on the queue if a free slot
        is immediately available, else raise the Full exception ('timeout'
        is ignored in that case).
        '''
        with self.not_full:
            if self.maxsize > 0:
                if not block:
                    if self._qsize() >= self.maxsize:
                        raise Full
                elif timeout is None:
                    while self._qsize() >= self.maxsize:
                        self.not_full.wait()
                elif timeout < 0:
                    raise ValueError("'timeout' must be a non-negative number")
                else:
                    endtime = time() + timeout
                    while self._qsize() >= self.maxsize:
                        remaining = endtime - time()
                        if remaining <= 0.0:
                            raise Full
                        self.not_full.wait(remaining)
            self._put(item)
            self.unfinished_tasks += 1
            self.not_empty.notify()
        '''
        將項目放入隊列;
        若是可選的參數block爲true,而且參數timeout爲None(默認值)時,則表示隊列需直到空閒時纔可用;
        若是參數timeout爲一個非負數,則表示它最多阻塞「超時」多少秒,而且若是在那個時間內隊列沒有空餘槽,則引起Full異常;
        而當參數block爲false時,則隊列有空餘槽時,就當即向項目放入隊列中,不然引起Full異常(這種狀況下,參數timeout不起做用)
        '''
    def get(self, block=True, timeout=None):
        '''Remove and return an item from the queue.
        If optional args 'block' is true and 'timeout' is None (the default),
        block if necessary until an item is available. If 'timeout' is
        a non-negative number, it blocks at most 'timeout' seconds and raises
        the Empty exception if no item was available within that time.
        Otherwise ('block' is false), return an item if one is immediately
        available, else raise the Empty exception ('timeout' is ignored
        in that case).
        '''
        with self.not_empty:
            if not block:
                if not self._qsize():
                    raise Empty
            elif timeout is None:
                while not self._qsize():
                    self.not_empty.wait()
            elif timeout < 0:
                raise ValueError("'timeout' must be a non-negative number")
            else:
                endtime = time() + timeout
                while not self._qsize():
                    remaining = endtime - time()
                    if remaining <= 0.0:
                        raise Empty
                    self.not_empty.wait(remaining)
            item = self._get()
            self.not_full.notify()
            return item
        '''
        從隊列中刪除並返回項目;
        若是可選的參數block爲true,而且參數timeout爲None(默認值)時,則表示隊列需直到有項目時纔可用;
        若是參數timeout爲一個非負數,則表示它最多阻塞「超時」多少秒,而且若是在那個時間內沒有可用的項目,則引起Empty異常;
        而當參數block爲false時,則項目可用就當即返回結果,不然引起Empty異常(這種狀況下,參數timeout不起做用)
        '''
    def put_nowait(self, item):
        '''Put an item into the queue without blocking.
        Only enqueue the item if a free slot is immediately available.
        Otherwise raise the Full exception.
        '''
        return self.put(item, block=False)
        '''
        沒有阻塞時將項目放入隊列;
        只有當隊列有空餘槽時,纔將項目入列;
        不然引起Full異常;
        '''
    def get_nowait(self):
        '''Remove and return an item from the queue without blocking.
        Only get an item if one is immediately available. Otherwise
        raise the Empty exception.
        '''
        return self.get(block=False)
        '''
        沒有阻塞時,從隊列中刪除並返回項目;
        只有當隊列有可用項目時,才獲取項目;
        不然引起Empty異常;
        '''
    # Override these methods to implement other queue organizations
    # (e.g. stack or priority queue).
    # These will only be called with appropriate locks held
    # Initialize the queue representation
    def _init(self, maxsize):
        self.queue = deque()
        '''
        初始化隊列;
        '''
    def _qsize(self):
        return len(self.queue)
    # Put a new item in the queue
    def _put(self, item):
        self.queue.append(item)
        '''
        將新項目放入隊列;
        '''
    # Get an item from the queue
    def _get(self):
        return self.queue.popleft()
        '''
        從隊列中獲取項目
        '''
Queue
相關文章
相關標籤/搜索