Python中可以使用append()方法向列表末尾添加元素,使用insert()方法在任意位置插入元素,使用extend()方法将另一个列表中的元素添加到当前列表末尾。
例如:
```
list1 = [1, 2, 3]
list1.append(4)
print(list1) # 输出 [1, 2, 3, 4]
list1.insert(1, 5)
print(list1) # 输出 [1, 5, 2, 3, 4]
list2 = [6, 7, 8]
list1.extend(list2)
print(list1) # 输出 [1, 5, 2, 3, 4, 6, 7, 8]
```
可以使用remove()方法删除列表中指定的元素,使用pop()方法删除列表中指定位置的元素,使用del语句删除列表中指定位置或整个列表。
例如:
```
list1 = [1, 5, 2, 3, 4, 6, 7, 8]
list1.remove(5)
print(list1) # 输出 [1, 2, 3, 4, 6, 7, 8]
list1.pop(2)
print(list1) # 输出 [1, 2, 4, 6, 7, 8]
del list1[0]
print(list1) # 输出 [2, 4, 6, 7, 8]
del list1
print(list1) # 报错,list1未定义
```