Remove Specified Item
The remove() method is used to delete a specific item from a list. It searches for the first occurrence of the specified value and removes it from the list. If the item is not found, Python will raise a ValueError. This method does not return a new list—it modifies the original list in place.
fruits = ['apple', 'banana', 'cherry', 'banana']
fruits.remove('banana')
print("Updated List:", fruits)
Do it
If there is more than one item in the list with the specified value, the remove() method will delete only the first occurrence. It scans the list from left to right and stops after removing the first matching item. The remaining items with the same value will stay in the list.
Do it
POP Method
The pop() method in Python removes the last item from a list by default and returns it. This method is useful when you need to both remove and retrieve the last element. Unlike remove(), which deletes a value by content, pop() works by position. If the list is empty and pop() is called without an index, it raises an IndexError. You can also provide an optional index to remove a specific item.
colors = ['red', 'green', 'blue']
last_color = colors.pop()
print("Removed Item:", last_color)
print("Updated List:", colors)
Do it
Del Keyword
The del keyword in Python is used to delete an item at a specific index in a list. Unlike remove() or pop(), del does not return the deleted item—it simply removes it. You can also use del to delete a slice of elements or even the entire list. If the specified index is out of range, Python will raise an IndexError.
fruits = ['apple', 'banana', 'cherry', 'date']
del fruits[1]
print("Updated List:", fruits)
Do it
Clear Method
The clear() method in Python is used to remove all items from a list, making it completely empty. It does not delete the list itself, only its contents. After calling this method, the list remains in memory as an empty list []. This is a quick and efficient way to reset a list without creating a new one.
numbers = [1, 2, 3, 4, 5]
numbers.clear()
print("Cleared List:", numbers)