How does del operator work on list in Python?

PythonServer Side ProgrammingProgramming

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.

raja
Published on 05-Jan-2018 16:25:36
Advertisements