方法 | 描述 |
---|---|
aList.append(obj) | 等同于aList[len(aList) :len(aList)] = [obj] |
aList.clear() | 删除aList的所有元素 |
aList.count(obj) | 返回aList中与obj相等的元素个数 |
aList.copy() | 返回aList的副本。请注意,这是浅复制,即不会复制元素 |
aList.extend(sequence) | 等同于aList[len(aList):len(aList)] = sequence |
aList.index(obj) | 返回aList中第一个与obj相等的元素的索引;如果没有这样的元素,就引发ValueError异常 |
aList.insert(index, obj) | 如果index >= 0,就等同于aList[index:index] = [obj];如果index < 0,就将指定的对象加入到列表开头 |
aList.pop([index]) | 删除并返回指定索引(默认为1)处的元素 |
aList.remove(obj) | 等同于del aList[aList.index(obj)] |
aList.reverse() | 就地按相反的顺序排列列表的元素 |
aList.sort([cmp][,key][,reverse]) | 就地对aList的元素进行排序(稳定排序)。可通过提供比较函数cmp、键函数key(创建用户排序的键)和降序标志reverse(一个布尔值)进行定制 |
Python中列表方法总结
最新推荐文章于 2022-12-30 20:09:16 发布