Source Code:
(back to article)
my_list = [1, 2, 3, 4, 5] # Find the index of the element you want to replace index_to_replace = my_list.index(3) # Replace the element at the specified index my_list[index_to_replace] = 6 print(my_list) # [1, 2, 6, 4, 5]
Result:
Report an issue