Python成長之路第二篇(2)_列表元組內置函數用法

列表元組內置函數用法list

元組的用法和列表相似就不一一介紹了

1)def append(self, p_object):將值添加到列表的最後

# real signature unknown; restored from __doc__

""" L.append(object) -- append object to end """

pass

(2)def count(self, value): 值的出現次數

# real signature unknown; restored from __doc__

""" L.count(value) -> integer -- return number of occurrences of value """

return 0

(3)def extend(self, iterable): 擴展列表通過添加元素

clip_p_w_picpath002

# real signature unknown; restored from __doc__

""" L.extend(iterable) -- extend list by appending elements from the iterable """

pass

(4)def index(self, value, start=None, stop=None): 返回第一次出現定義某隻的下標

# real signature unknown; restored from __doc__

"""

L.index(value, [start, [stop]]) -> integer -- return first index of value.

Raises ValueError if the value is not present.

"""

return 0

(5)def insert(self, index, p_object):指定下標插入元素

# real signature unknown; restored from __doc__

""" L.insert(index, object) -- insert object before index """

pass

(6)def pop(self, index=None):刪除並返回指定下標的值,如果沒有指定下標最後一個返回

clip_p_w_picpath004

# real signature unknown; restored from __doc__

"""

L.pop([index]) -> item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

"""

pass

(7)def remove(self, value): 移除列表中的指定值第一個

clip_p_w_picpath006

# real signature unknown; restored from __doc__

"""

L.remove(value) -- remove first occurrence of value.

Raises ValueError if the value is not present.

"""

pass

(8)def reverse(self): 翻轉

clip_p_w_picpath008

# real signature unknown; restored from __doc__

""" L.reverse() -- reverse *IN PLACE* """

pass

(9)def sort(self, cmp=None, key=None, reverse=False):比較大小

數字按照大小比較

中文按照unicode比較

# real signature unknown; restored from __doc__

"""

L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;

cmp(x, y) -> -1, 0, 1

"""

pass

(10)def __add__(self, y): 加

clip_p_w_picpath010

# real signature unknown; restored from __doc__

""" x.__add__(y) <==> x+y """

pass

(11)def __contains__(self, y):包含

# real signature unknown; restored from __doc__

""" x.__contains__(y) <==> y in x """

pass

(12)def __delitem__(self, y): 刪除單個序列元素

# real signature unknown; restored from __doc__

""" x.__delitem__(y) <==> del x[y] """

pass

(13)def __delslice__(self, i, j): 刪除序列片斷

# real signature unknown; restored from __doc__

"""

x.__delslice__(i, j) <==> del x[i:j]

Use of negative indices is not supported.

"""

pass

(14)def __eq__(self, y): 等於

# real signature unknown; restored from __doc__

""" x.__eq__(y) <==> x==y """

pass

(15)def __getattribute__(self, name): 取屬性;內建 getattr();總是被調用

# real signature unknown; restored from __doc__

""" x.__getattribute__('name') <==> x.name """

pass

(16)def __getitem__(self, y): 得到單個序列元素

# real signature unknown; restored from __doc__

""" x.__getitem__(y) <==> x[y] """

pass

(17)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.

"""

pass

(18)def __ge__(self, y):大於等於

# real signature unknown; restored from __doc__

""" x.__ge__(y) <==> x>=y """

pass

(19)def __gt__(self, y):大於

# real signature unknown; restored from __doc__

""" x.__gt__(y) <==> x>y """

pass

(20)def __iadd__(self, y):

# real signature unknown; restored from __doc__

""" x.__iadd__(y) <==> x+=y """

pass

(21)def __imul__(self, y):

# real signature unknown; restored from __doc__

""" x.__imul__(y) <==> x*=y """

pass

(22)def __init__(self, seq=()): _init__方法在類的一個對象被建立時,馬上運行

# known special case of list.__init__

"""

list() -> new empty list

list(iterable) -> new list initialized from iterable's items

# (copied from class doc)

"""

pass

(23)def __iter__(self): 創建迭代類;內建 iter()

# real signature unknown; restored from __doc__

""" x.__iter__() <==> iter(x) """

pass

(24)def __len__(self): 序列中項的數目長度

# real signature unknown; restored from __doc__

""" x.__len__() <==> len(x) """

pass

(25)def __le__(self, y):小於等於

# real signature unknown; restored from __doc__

""" x.__le__(y) <==> x<=y """

pass

(26)def __lt__(self, y):小於

# real signature unknown; restored from __doc__

""" x.__lt__(y) <==> x<y """

pass

(27)def __mul__(self, n): 重複;*操作符相乘

# real signature unknown; restored from __doc__

""" x.__mul__(n) <==> x*n """

pass

@staticmethod # known case of __new__

(28)def __new__(S, *more) 構造器(帶一些可選的參數) ;通常用在設置不變數據類型的子類。

: # real signature unknown; restored from __doc__

""" T.__new__(S, ...) -> a new object with type S, a subtype of T """

pass

(29)def __ne__(self, y):不等於

# real signature unknown; restored from __doc__

""" x.__ne__(y) <==> x!=y """

pass

(30)def __repr__(self): 對機器友好

real signature unknown; restored from __doc__

""" x.__repr__() <==> repr(x) """

pass

(31)def __reversed__(self): 接受一個序列作爲參數,返回一個以逆序訪問的迭代器(PEP 322)

# real signature unknown; restored from __doc__

""" L.__reversed__() -- return a reverse iterator over the list """

pass

(32)def __rmul__(self, n): 反向相乘

# real signature unknown; restored from __doc__

""" x.__rmul__(n) <==> n*x """

pass

(33)def __setitem__(self, i, y): 設置單個序列元素

# real signature unknown; restored from __doc__

""" x.__setitem__(i, y) <==> x[i]=y """

pass

(34)def __setslice__(self, i, j, y): 設置序列片斷

# real signature unknown; restored from __doc__

"""

x.__setslice__(i, j, y) <==> x[i:j]=y

Use of negative indices is not supported.

"""

pass

(35)def __sizeof__(self): 查看佔用內存的函數

# real signature unknown; restored from __doc__

""" L.__sizeof__() -- size of L in memory, in bytes """

pass

__hash__ = None

list

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章