示例示例### 增使用`insert()`函数可以在指定位置插入一个元素:
### 增
使用`insert()`函数可以在指定位置插入一个元素:
python
list = [1, 2, 3]
list.insert(1, 4)
print(list) # [1, 4, 2, 3]
### 删
使用`remove()`函数可以删除指定元素:
python
list = [1, 2, 3]
list.remove(2)
print(list) # [1, 3]
### 改
使用索引可以改变指定位置的元素:
python
list = [1, 2, 3]
list[1] = 4
print(list) # [1, 4, 3]
### 查
使用`index()`函数可以查找指定元素的索引:
python
list = [1, 2, 3]
index = list.index(2)
print(index) # 1
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(40条)