python 列表删除元素
python 删除元素的几种方式
方式一:使用del方法
>>> names=['Alice','Beth','Cecil','Dee-Dee','Earl'] >>> names ['Alice', 'Beth', 'Cecil', 'Dee-Dee', 'Earl'] >>> del names[2] >>> names ['Alice', 'Beth', 'Dee-Dee', 'Earl'] >>>
立即学习“Python免费学习笔记(深入)”;
>>> numbers=['a', 'b', 'c', 'd'] >>> numbers ['a', 'b', 'c', 'd'] >>> del numbers[1:3] >>> numbers ['a', 'd']
方式二:分片赋值
立即学习“Python免费学习笔记(深入)”;
>>> numbers=['a', 'b', 'c', 'd'] >>> numbers ['a', 'b', 'c', 'd'] >>> numbers[1:3]=[] >>> numbers ['a', 'd']
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号