Google News
logo
Python Program to Remove an item at a specified index
In the following example of Python program to remove an item from a list at a specified index :
Program :
my_list = [1, 2, 3, 4, 5]
print("Original List: ", my_list)

# Remove item at index 2
index_to_remove = 2
my_list.pop(index_to_remove)
print("List after removing item at index", index_to_remove, ":", my_list)
Output :
Original List:  [1, 2, 3, 4, 5]
List after removing item at index 2 : [1, 2, 4, 5]
In the above example, we have a list `my_list` with five items. We want to remove an item at a specified index (2 in this case) from the list.

We can use the `pop()` method to remove an item from a list at a specified index. After removing the item, we print the list to verify that the item has been removed.