Removing elements from a list using the del operator in Python
Using the del operator, you can remove an element from a list by its index:
lst = [1, 2, 3]
del lst[0]
print(lst) # [2, 3]
After applying the del operator, all elements following the deleted one are shifted forward to take its place. In doing so, the length of the list itself becomes shorter by 1.
Given a list:
lst = ['a', 'b', 'c', 'd', 'e']
Remove the element with number 1.
Given a list:
lst = ['a', 1, 'b', 2, 'c', 3]
Leave only string elements in the list.