How to Add an Item to List At Specified Index in Python


In this example we will show how to add an item to the list at the specified index in Python.

Source Code

my_list = ['a', 'b', 'c', 'd', 'e']
my_list.insert(2, 'f')
print(my_list)

Output:

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