自学Python-列表list(object) 元组tuple(object) 方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自学Python-列表list(object) 元组tuple(object) 方法相关的知识,希望对你有一定的参考价值。
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
? 列表简介:
o 列表是序列对象,可包含任意的Python数据信息,如字符串、数字、列表、元组等
o 列表的数据是可变的,我们可通过对象方法对列表中的数据进行增加、修改、删除等操作
o 可以通过list(seq)函数把一个序列类型转换成一个列表
1.append(x),在列表尾部追加单个对象x,使用多个参数会引起异常
append(self, p_object)
1. |
>>>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) 方法的主要内容,如果未能解决你的问题,请参考以下文章