python列表操作方法

2020-09-05 12:20:00
六月
来源:
https://www.cnblogs.com/wj-1314/p/8433116.html
转贴 543
序号 函数 描述
1 list.append(self,p_object) 给列表后面追加新的对象
2 list.clear(self) 清空列表中的元素
3 list.copy(self) 浅复制列表
4 list.count(self,value) 统计某个元素在列表中出现的次数
5 list.extend(self,iterable) 在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)
6

list.index(self, value, start=None, stop=None)

从列表中找出某个值第一个匹配项的索引位置
7 list.insert(self,index,start=None,stop=None) 将对象插入列表
8 list.pop(self,index=None) 移除列表中的一个元素(默认最后一个),并返回该元素的值
9 list.remove(self,value) 移除列表中某个值的第一个匹配项,从左找到第一个指定元素
10 list.reverse(self,value) 反向列表中的元素
11 list.sort(self,key=None,reverse=False) 对原列表进行排序


发表评论
评论通过审核后显示。