How to Remove List Item of Specified Index in Python


In this example we will show how to remove the list item of the specified index using the del keyword in Python.

Source Code

my_list = ['a', 'b', 'c', 'd', 'e']
del my_list[2]
print(my_list)

Output:

['a', 'b', 'd', 'e']

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

How to Remove List Item of Specified Index in Python


In this example we will show how to remove the list item of the specified index using the pop() method in Python.

Source Code

my_list = ['a', 'b', 'c', 'd', 'e']
my_list.pop(2)    #  index is specified
print(my_list)
my_list.pop()     # index is not specified
print(my_list)

Output:

['a', 'b', 'd', 'e']
['a', 'b', 'd']
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments