对列表的增删改:
>>> s['ok', 'The', 'fox', 'when', 'small', 'iss']
>>> s.insert(2,'key')
>>> s
['ok', 'The', 'key', 'fox', 'when', 'small', 'iss']
>>> s.append('find')
>>> s
['ok', 'The', 'key', 'fox', 'when', 'small', 'iss', 'find']
>>> s.remove('iss')
>>> s
['ok', 'The', 'key', 'fox', 'when', 'small', 'find']
>>> s.index('fox')
35.4 Python中对列表的增删改
最新推荐文章于 2024-10-29 21:10:39 发布
本文通过一个简单的Python列表操作示例,介绍了如何使用insert方法在指定位置插入元素、append方法在列表末尾添加元素、remove方法删除指定元素以及index方法查找元素的位置。
8万+

被折叠的 条评论
为什么被折叠?



