class list(object)
| list() -> new empty list #创建一个新的空列表
| list(iterable) -> new list initialized from iterable's items #迭代变量初始化新列表
|
| Methods defined here:
| | __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __delitem__(self, key, /)
| Delete self[key].
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __gt__(self, value, /)
| Return self>value.
|
| __iadd__(self, value, /)
| Implement self+=value.
|
| __imul__(self, value, /)
| Implement self*=value.
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self, /)
| Implement iter(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __len__(self, /)
| Return len(self).
|
| __lt__(self, value, /)
| Return self<value.
|
| __mul__(self, value, /)
| Return self*value.n
|
| __ne__(self, value, /)
| Return self!=value.
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __repr__(self, /)
| Return repr(self).
|
| __reversed__(...)
| L.__reversed__() -- return a reverse iterator over the list
|
| __rmul__(self, value, /)
| Return self*value.
|
| __setitem__(self, key, value, /)
| Set self[key] to value.
|
| __sizeof__(...)
| L.__sizeof__() -- size of L in memory, in bytes
|
| append(...) #增加一个元素到list最后
| L.append(object) -> None -- append object to end
|
| clear(...) #清空列表
| L.clear() -> None -- remove all items from L
|
| copy(...)
| L.copy() -> list -- a shallow copy of L
|
| count(...) #统计list中元素个数
| L.count(value) -> integer -- return number of occurrences of value
|
| extend(...)
| L.extend(iterable) -> None -- extend list by appending elements from the iterable
|
| index(...) #查找list中某个元素的下标值,并返回下标值
| L.index(value, [start, [stop]]) -> integer -- return first index of value.
| Raises ValueError if the value is not present.
|
| insert(...) #在index下标位置,插入元素object
| L.insert(index, object) -- insert object before index
|
| pop(...) #弹出列表中元素,默认弹出最后一位,index表示元素下标
| L.pop([index]) -> item -- remove and return item at index (default last).
| Raises IndexError if list is empty or index is out of range.
|
| remove(...) #移除列表中的元素
| L.remove(value) -> None -- remove first occurrence of value.
| Raises ValueError if the value is not present.
|
| reverse(...) #倒序排列列表中的元素
| L.reverse() -- reverse *IN PLACE*
|
| sort(...) #排序
| L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*
|
>>> a
[]
>>> a.append(1)
>>> a
[1]
>>> a.__add__
<method-wrapper '__add__' of list object at 0x01780968>
>>> a.__add__(2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "int") to list
>>> b = [2]
>>> a.__add__(b)
[1, 2]
>>> a.__repr__()
'[1]'
>>> a.append(2)
>>> a
[1, 2]
>>> a.reserve()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'reserve'
>>> a.reverse()
>>> a
[2, 1]
>>> a.reverse()
>>> a
[1, 2]
>>> a = list(range(10))
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a.remove()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: remove() takes exactly one argument (0 given)
>>> a.remove(2)
>>> a
[0, 1, 3, 4, 5, 6, 7, 8, 9]
>>> b =a.pop()
>>> b
9
>>> b =a.pop()
>>> b
8
>>> a
[0, 1, 3, 4, 5, 6, 7]
>>> b =a.pop(5)
>>> b
6
>>> a
[0, 1, 3, 4, 5, 7]
>>> b =a.pop(0)
>>> a
[1, 3, 4, 5, 7]
>>> b =a.pop(0)
>>> b
1
>>> a.insert(3,22)
>>> a
[3, 4, 5, 22, 7]
>>> a.index(5)
2
>>> a
[3, 4, 5, 22, 7]
>>> a.index(2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: 2 is not in list