Python/The del statement
[i]Learn· Data Structures

The del statement

There is a way to remove an item from a list given its index instead of its value: the del statement. This differs from the pop() method which returns a value. The del statement can also be used to remove slices from a list or clear the entire list (which we did earlier by assignment of an empty list to the slice). For example:

>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0]
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4]
>>> a
[1, 66.25, 1234.5]
>>> del a[:]
>>> a
[]

del can also be used to delete entire variables:

>>> del a

Referencing the name a hereafter is an error (at least until another value is assigned to it). We’ll find other uses for del later.

Source: Data Structures by Python Software Foundation, licensed under PSF-2.0. Retrieved 2026-11-18. Changes: Extracted section 5.2 from The Python Tutorial (Python 3.14), https://docs.python.org/3.14/tutorial/datastructures.html; removed section numbers, permalinks and site navigation; code blocks kept as shown; runnable examples: prompts and output lines removed; examples that use names defined earlier in the section start with the source statements that define them.