Computer >> Computer tutorials >  >> Programming >> Python

How does del operator work on list in Python?


The del operator removes a specific index from given list. For example, if you want to remove the element on index 1 from list a, you'd use:

Example

a = [3, "Hello", 2, 1]
del a[1]
print(a)

Output

This will give the output −

[3, 2, 1]

Note that del removes the elements in place, ie, it doesn't create a new list.