all Python 3operatorfunction
operator.delitem
sequences
Item deletion: del a[b].
Syntax
operator.delitem(a, b)
Like del a[b] it supports slices: delitem(xs, slice(0, 2)) removes the first two items. A missing key raises KeyError — if the key may be absent use dict.pop(key, None). Deleting from the front of a list shifts every other item, so a queue is better served by collections.deque.
Examples
import operator
l = [1, 2, 3]
operator.delitem(l, 1)
print(l) # → [1, 3]
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy