建站网站模板下载,竹木工艺品网站建设,上市公司查询网站,买号链接python#xff1a;list类型中所有的方法#xff0c;每一种方法附带一个实例#xff1a;以及解释说明 文章目录 python#xff1a;list类型中所有的方法#xff0c;每一种方法附带一个实例#xff1a;以及解释说明list类型中所有的方法#xff08;行为#xff09;获取方…pythonlist类型中所有的方法每一种方法附带一个实例以及解释说明 文章目录 pythonlist类型中所有的方法每一种方法附带一个实例以及解释说明list类型中所有的方法行为获取方式实例详细解释每一个都带有详细讲解appendclearcopycountextendindexinsertpopremovereversesort list类型中所有的方法行为
获取方式
通过help函数获取
实例
help(list)# 输出内容
Help on class list in module builtins:class list(object)| list(iterable(), /)| | Built-in mutable sequence.| | If no argument is given, the constructor creates a new empty list.| The argument must be an iterable if specified.| | Methods defined here:| | __add__(self, value, /)| Return selfvalue.| | __contains__(self, key, /)| Return key in self.| | __delitem__(self, key, /)| Delete self[key].| | __eq__(self, value, /)| Return selfvalue.| | __ge__(self, value, /)| Return selfvalue.| | __getattribute__(self, name, /)| Return getattr(self, name).| | __getitem__(...)| x.__getitem__(y) x[y]| | __gt__(self, value, /)| Return selfvalue.| | __iadd__(self, value, /)| Implement selfvalue.| | __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 selfvalue.| | __len__(self, /)| Return len(self).| | __lt__(self, value, /)| Return selfvalue.| | __mul__(self, value, /)| Return self*value.| | __ne__(self, value, /)| Return self!value.| | __repr__(self, /)| Return repr(self).| | __reversed__(self, /)| Return a reverse iterator over the list.| | __rmul__(self, value, /)| Return value*self.| | __setitem__(self, key, value, /)| Set self[key] to value.| | __sizeof__(self, /)| Return the size of the list in memory, in bytes.| | append(self, object, /)| Append object to the end of the list.| | clear(self, /)| Remove all items from list.| | copy(self, /)| Return a shallow copy of the list.| | count(self, value, /)| Return number of occurrences of value.| | extend(self, iterable, /)| Extend list by appending elements from the iterable.| | index(self, value, start0, stop9223372036854775807, /)| Return first index of value.| | Raises ValueError if the value is not present.| | insert(self, index, object, /)| Insert object before index.| | pop(self, index-1, /)| Remove and return item at index (default last).| | Raises IndexError if list is empty or index is out of range.| | remove(self, value, /)| Remove first occurrence of value.| | Raises ValueError if the value is not present.| | reverse(self, /)| Reverse *IN PLACE*.| | sort(self, /, *, keyNone, reverseFalse)| Sort the list in ascending order and return None.| | The sort is in-place (i.e. the list itself is modified) and stable (i.e. the| order of two equal elements is maintained).| | If a key function is given, apply it once to each list item and sort them,| ascending or descending, according to their function values.| | The reverse flag can be set to sort in descending order.| | ----------------------------------------------------------------------| Class methods defined here:| | __class_getitem__(...) from builtins.type| See PEP 585| | ----------------------------------------------------------------------| Static methods defined here:| | __new__(*args, **kwargs) from builtins.type| Create and return a new object. See help(type) for accurate signature.| | ----------------------------------------------------------------------| Data and other attributes defined here:| | __hash__ None
这里有所有关于list的行为或者方法我们这里选取这些行为 | append(self, object, /)| Append object to the end of the list.| | clear(self, /)| Remove all items from list.| | copy(self, /)| Return a shallow copy of the list.| | count(self, value, /)| Return number of occurrences of value.| | extend(self, iterable, /)| Extend list by appending elements from the iterable.| | index(self, value, start0, stop9223372036854775807, /)| Return first index of value.| | Raises ValueError if the value is not present.| | insert(self, index, object, /)| Insert object before index.| | pop(self, index-1, /)| Remove and return item at index (default last).| | Raises IndexError if list is empty or index is out of range.| | remove(self, value, /)| Remove first occurrence of value.| | Raises ValueError if the value is not present.| | reverse(self, /)| Reverse *IN PLACE*.| | sort(self, /, *, keyNone, reverseFalse)| Sort the list in ascending order and return None.| | The sort is in-place (i.e. the list itself is modified) and stable (i.e. the| order of two equal elements is maintained).| | If a key function is given, apply it once to each list item and sort them,| ascending or descending, according to their function values.| | The reverse flag can be set to sort in descending order.详细解释每一个都带有详细讲解
append
解释内容
append(self, object, /) Append object to the end of the list.
参数
self默认参数表示是当前从类中实例化出来的对象object添加的对象/限制参数表示在/之前的参数都是仅位置参数
作用
Append object to the end of the list.添加对象到list的末尾
clear
解释内容
clear(self, /) Remove all items from list.
参数
self默认参数表示是当前从类中实例化出来的对象/限制参数表示在/之前的参数都是仅位置参数
作用
Remove all items from list.清除list中的全部元素
copy
解释内容
copy(self, /) Return a shallow copy of the list.
参数
self默认参数表示是当前从类中实例化出来的对象/限制参数表示在/之前的参数都是仅位置参数
作用
Return a shallow copy of the list.返回list的浅拷贝副本
注意
这里浅拷贝的意思为 直接把在原list上面进行拷贝 遇到list嵌套list的时候这种可变数据类型时会出现同时变动的情况。
count
解释内容
count(self, value, /) Return number of occurrences of value.
参数
self默认参数表示是当前从类中实例化出来的对象value统计的值/限制参数表示在/之前的参数都是仅位置参数
作用
Return number of occurrences of value.返回值出现的次数
extend
解释内容
extend(self, iterable, /) Extend list by appending elements from the iterable.
参数
self默认参数表示是当前从类中实例化出来的对象iterable可迭代的可迭代的对象/限制参数表示在/之前的参数都是仅位置参数
作用
Extend list by appending elements from the iterable.通过可迭代对象中的元素来扩展list
index
解释内容
index(self, value, start0, stop9223372036854775807, /) Return first index of value.Raises ValueError if the value is not present.
参数
self默认参数表示是当前从类中实例化出来的对象value需要查找的值start0默认参数指从0开始stop9223372036854775807默认参数指至9223372036854775807结束/限制参数表示在/之前的参数都是仅位置参数
作用
返回指定值第一次出现的索引值
注意如果值不存在则返回ValueError的错误
insert
解释内容
insert(self, index, object, /) nsert object before index.
参数
self默认参数表示是当前从类中实例化出来的对象index插入的位置索引object插入的元素/限制参数表示在/之前的参数都是仅位置参数
作用
在索引之前插入对象
pop
解释内容
pop(self, index-1, /) Remove and return item at index (default last). Raises IndexError if list is empty or index is out of range.
参数
self默认参数表示是当前从类中实例化出来的对象index-1默认参数默认操作最后一个元素/限制参数表示在/之前的参数都是仅位置参数
作用
移除并返回指定索引的元素如为指定索引则默认为最后一个元素
注意如果为空列表或者索引超过范围则会报IndexError错误
remove
解释内容
remove(self, value, /) Remove first occurrence of value. Raises ValueError if the value is not present.
参数
self默认参数表示是当前从类中实例化出来的对象value要移除的值/限制参数表示在/之前的参数都是仅位置参数
作用
移除第一次出现的值
注意如果值不存在则会报ValueError错误
reverse
解释内容
reverse(self, /) Reverse IN PLACE.
参数
self默认参数表示是当前从类中实例化出来的对象/限制参数表示在/之前的参数都是仅位置参数
作用
IN PLACE在原地在原地反转 – 倒序
sort
解释内容
sort(self, /, *, keyNone, reverseFalse) Sort the list in ascending order and return None.
参数
self默认参数表示是当前从类中实例化出来的对象/限制参数表示在/之前的参数都是仅位置参数*限制参数表示在 * 之后的参数都是关键字参数keyNone默认返回NonereverseFalse默认不反转顺序
作用
用来给容器排序