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
list.pop
Removes and returns the item at position i (default -1, the last item). Raises IndexError on an empty list or an out-of-range index.
list.clear
Removes all items from the list in place. Equivalent to `del lst[:]`; returns None.
list[i] / list[i:j:k]
Subscript syntax to read a single element (by index) or a new list (by slice). Slicing always returns a new shallow copy; out-of-range slice bounds are silently clamped while single-index access raises IndexError.
list.remove
Removes the first occurrence of a value equal to x from the list. Raises ValueError if x is not present; returns None.
← All Python list methods · Dict methods · list vs tuple vs set