1.刪除第一個匹配數據:
>>> a = [0, 2, 3, 2] >>> a.remove(2) >>> a [0, 3, 2]
2.根據index刪除數據:
>>> a = [9, 8, 7, 6] >>> del a[1] >>> a [9, 7, 6]
3.根據index刪除數據並返回該數據:
>>> a = [4, 3, 5] >>> a.pop(1) 3 >>> a [4, 5]
4. 在循環中刪除元素:
a = ["a", "b", "c", "d", "e"] for item in a[:]: print item if item == "b": a.remove(item)