remove

del list[...]

Statement that deletes the element or slice at the given position, mutating the list in place. Unlike pop() it does not return the removed value; unlike remove() it targets by index, not by value.

del list[i]   |   del list[i:j]

Parameters

Parameter Purpose
del lst[i] Delete a single index; raises IndexError if out of range.
del lst[i:j] Delete a slice; empties the range without error even if bounds exceed the list.
del lst[:] Delete all elements — equivalent to lst.clear().

Examples

>>> lst = [1, 2, 3, 4]
>>> del lst[1]
>>> lst
[1, 3, 4]

Deletes single index.

>>> lst = [1, 2, 3, 4, 5]
>>> del lst[1:4]
>>> lst
[1, 5]

Slice deletion.

>>> lst = [1, 2, 3]
>>> del lst[9]
IndexError: list assignment index out of range

Single-index del raises; slice del does not.

>>> lst = [1, 2, 3]
>>> del lst[:]
>>> lst
[]

del lst[:] mirrors clear().

Gotcha

del is a statement, not a method — you cannot call it or pass it as a callback. Single-index del raises IndexError; slice del silently no-ops on empty ranges.

Related methods

← All Python list methods · Dict methods · list vs tuple vs set