Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 478 Bytes

80.md

File metadata and controls

26 lines (19 loc) · 478 Bytes
rank vote view answer url
80 1541 2672492 18 url

如何删除 list 中指定 index 的元素?


使用 del 并且指定你想删除的元素的 index:

>>> a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> del a[-1]
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8]

同时支持切片:

>>> del a[2:4]
>>> a
[0, 1, 4, 5, 6, 7, 8, 9]