自學Python-列表list(object) 元組tuple(object) 方法

來源:互聯網
上載者:User

標籤:append   logs   iterator   red   top   通過   ==   als   url   

Python List方法總結 
class list(object):    """    list() -> new empty list    list(iterable) -> new list initialized from iterable‘s items    """    def append(self, p_object): # real signature unknown; restored from __doc__        """ L.append(object) -> None -- append object to end """        pass    def clear(self): # real signature unknown; restored from __doc__        """ L.clear() -> None -- remove all items from L """        pass    def copy(self): # real signature unknown; restored from __doc__        """ L.copy() -> list -- a shallow copy of L """        return []    def count(self, value): # real signature unknown; restored from __doc__        """ L.count(value) -> integer -- return number of occurrences of value """        return 0    def extend(self, iterable): # real signature unknown; restored from __doc__        """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """        pass    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    def insert(self, index, p_object): # real signature unknown; restored from __doc__        """ L.insert(index, object) -- insert object before index """        pass    def pop(self, index=None): # 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    def remove(self, value): # real signature unknown; restored from __doc__        """        L.remove(value) -> None -- remove first occurrence of value.        Raises ValueError if the value is not present.        """        pass    def reverse(self): # real signature unknown; restored from __doc__        """ L.reverse() -- reverse *IN PLACE* """        pass    def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__        """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """        pass    def __add__(self, *args, **kwargs): # real signature unknown        """ Return self+value. """        pass    def __contains__(self, *args, **kwargs): # real signature unknown        """ Return key in self. """        pass    def __delitem__(self, *args, **kwargs): # real signature unknown        """ Delete self[key]. """        pass    def __eq__(self, *args, **kwargs): # real signature unknown        """ Return self==value. """        pass    def __getattribute__(self, *args, **kwargs): # real signature unknown        """ Return getattr(self, name). """        pass    def __getitem__(self, y): # real signature unknown; restored from __doc__        """ x.__getitem__(y) <==> x[y] """        pass    def __ge__(self, *args, **kwargs): # real signature unknown        """ Return self>=value. """        pass    def __gt__(self, *args, **kwargs): # real signature unknown        """ Return self>value. """        pass    def __iadd__(self, *args, **kwargs): # real signature unknown        """ Implement self+=value. """        pass    def __imul__(self, *args, **kwargs): # real signature unknown        """ Implement self*=value. """        pass    def __init__(self, seq=()): # known special case of list.__init__        """        list() -> new empty list        list(iterable) -> new list initialized from iterable‘s items        # (copied from class doc)        """        pass    def __iter__(self, *args, **kwargs): # real signature unknown        """ Implement iter(self). """        pass    def __len__(self, *args, **kwargs): # real signature unknown        """ Return len(self). """        pass    def __le__(self, *args, **kwargs): # real signature unknown        """ Return self<=value. """        pass    def __lt__(self, *args, **kwargs): # real signature unknown        """ Return self<value. """        pass    def __mul__(self, *args, **kwargs): # real signature unknown        """ Return self*value.n """        pass    @staticmethod # known case of __new__    def __new__(*args, **kwargs): # real signature unknown        """ Create and return a new object.  See help(type) for accurate signature. """        pass    def __ne__(self, *args, **kwargs): # real signature unknown        """ Return self!=value. """        pass    def __repr__(self, *args, **kwargs): # real signature unknown        """ Return repr(self). """        pass    def __reversed__(self): # real signature unknown; restored from __doc__        """ L.__reversed__() -- return a reverse iterator over the list """        pass    def __rmul__(self, *args, **kwargs): # real signature unknown        """ Return self*value. """        pass    def __setitem__(self, *args, **kwargs): # real signature unknown        """ Set self[key] to value. """        pass    def __sizeof__(self): # real signature unknown; restored from __doc__        """ L.__sizeof__() -- size of L in memory, in bytes """        pass    __hash__ = None
list源碼

? 列表簡介:
o 列表是序列對象,可包含任意的Python資料資訊,如字串、數字、列表、元組等
o 列表的資料是可變的,我們可通過對象方法對列表中的資料進行增加、修改、刪除等操作
o 可以通過list(seq)函數把一個序列類型轉換成一個列表
1.append(x),在列表尾部追加單個對象x,使用多個參數會引起異常

     append(self, p_object)

1.
2.
3.
4.

>>>lst=[1,2,3]
>>>relust=lst.append(4)
>>>print result
[1,2,3,4]



2.count(x),返回對象x在列表中出現的次數
3.extend(L),將列表L中的表項添加到列表中,返回None
4.Index(x),返回列表中匹配對象x的第一個清單項目的索引,無匹配元素時產生異常
5.insert(i,x),在索引為i的元素前插入對象x,如list.insert(0,x)在第一項前插入對象,返回None
6.pop(x),刪除列表中索引為x的表項,並返回該表項的值,若未指定索引,pop返回列表最後一項
7.remove(x),刪除列表中匹配對象x的第一個元素,匹配元素時產生異常,返回None
8.reverse(),顛倒列表元素的順序
9.sort(),對列表排序,返回none,bisect模組可用於排序清單項目的添加和刪除

 

自學Python-列表list(object) 元組tuple(object) 方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.