是,remove删除第一个匹配值,而不是特定索引:
>>> a = [0, 2, 2, 3]
>>> a.remove(2)
>>> a
[0, 2, 3]
del删除一个特定的索引:
>>> a = [3, 2, 2, 1]
>>> del a[1]
[3, 2, 1]
和pop返回删除的元素:
>>> a = [4, 3, 5]
>>> a.pop(1)
3
>>> a
[4, 5]
他们的错误模式也不同:
>>> a = [4, 5, 6]
>>> a.remove(7)
Traceback (most recent call last):
File "", line 1, in
ValueError: list.remove(x): x not in list
>>> del a[7]
Traceback (most recent call last):
File "", line 1, in
IndexError: list assignment index out of range
>>> a.pop(7)
Traceback (most recent call last):
File "", line 1, in
IndexError: pop index out of range