python 列表类型方法总结

列表:元素可以增加,删除,修改,以下方法使用后,原列表改变

1.append(self, p_object)->None:向列表追加元素,放在列表最后,p_object作为一个元素

2.clear(self)->None: 清空列表

3.copy(self)->list:拷贝列表,浅拷贝

4.count(self, value)->int: 参数value在列表中出现的次数

5.extend(self, iterable)->None:扩展列表,遍历iterable序列,逐个添加到list中

6.index(self, value, start=None, stop=None)->int:返回value在list中的索引值,如果不存在,会报错

7.insert(self, index, p_object)->None:向列表插入元素,放在index的前面

8.pop(self, index=None)->item(返回删除的元素):列表删除元素,默认删除最后一个元素,index如果不存在,抛出IndexError异常

9.remove(self, value)->None:删除第一个出现的value,如果value不存在,抛出ValueError异常

10.reverse(self)->None:列表反转

11.sort(self, key=None, reverse=False)->None:列表排序

猜你喜欢

转载自www.cnblogs.com/itrain/p/9021295.html