In Post #50, we learned how to grow lists using methods like .append()
and .insert()
. But the mutability of lists (which we discussed in Post #49) also means we can shrink them. Removing items is just as common and important as adding them.
In this post, we’ll explore the three primary ways to remove items from a Python list: the .remove()
method, the .pop()
method, and the del
keyword. Each one works differently, and learning when to use each will make your code more precise and effective.
.remove()
: Removing an Item by Its Value
Use the .remove()
method when you know the value of the item you want to remove, but not necessarily its position (index).
The syntax is: my_list.remove(value_to_remove)
Let’s say we have a shopping list and we’ve already found the bread.
shopping_list = ["milk", "eggs", "bread", "apples"]
print(f"Initial list: {shopping_list}")
shopping_list.remove("bread")
print(f"After removing 'bread': {shopping_list}")
The output will be:
Initial list: ['milk', 'eggs', 'bread', 'apples']
After removing 'bread': ['milk', 'eggs', 'apples']
Two important things to know about .remove()
:
- It only removes the first matching value it finds in the list.
- If the value is not in the list, your program will crash with a
ValueError
.
.pop()
: Removing an Item by Its Index (and Getting it Back)
Use the .pop()
method when you want to remove an item at a specific index. Crucially, .pop()
does two things: it removes the item, and it returns the value that was removed, so you can save it to another variable.
The syntax is: removed_item = my_list.pop(index)
Popping from a Specific Index
Let’s imagine our list is a queue of tasks, and we want to complete the first task.
tasks = ["Pay bills", "Call mom", "Do laundry"]
print(f"Tasks: {tasks}")
# Remove the item at index 0 and store it in a variable
first_task = tasks.pop(0)
print(f"Just completed: {first_task}")
print(f"Remaining tasks: {tasks}")
The output shows the first item being removed and captured:
Tasks: ['Pay bills', 'Call mom', 'Do laundry']
Just completed: Pay bills
Remaining tasks: ['Call mom', 'Do laundry']
Popping from the End
If you call .pop()
without an index, it has a special, very common behavior: it removes and returns the last item in the list.
# Assuming 'tasks' is now ['Call mom', 'Do laundry']
last_task = tasks.pop()
print(f"Just completed: {last_task}")
print(f"Remaining tasks: {tasks}")
The output will be:
Just completed: Do laundry
Remaining tasks: ['Call mom']
The del
Keyword: Simple Deletion by Index
The del
keyword is a general-purpose statement in Python used to delete objects. You can use it to remove an item from a list at a specific index. Unlike .pop()
, del
does not return the value it removes—it’s gone for good.
The syntax is: del my_list[index]
Use del
when you simply want to remove an item by its position and you don’t need to use the removed value for anything else.
numbers = [10, 20, 30, 40, 50]
print(f"Numbers before: {numbers}")
# Delete the item at index 2 (the number 30)
del numbers[2]
print(f"Numbers after: {numbers}")
The output is:
Numbers before: [10, 20, 30, 40, 50]
Numbers after: [10, 20, 40, 50]
Summary: Which One Should You Use?
Here’s a simple guide to help you choose:
- Use
.remove(value)
when you know what you want to remove. - Use
.pop(index)
when you want to remove an item by its position AND you need to use the removed item. - Use
del my_list[index]
when you want to remove an item by its position AND you don’t care about the removed item.
What’s Next?
You now have a complete set of tools for both adding to and removing from lists. Understanding the difference between removing by value and removing by index is key to effectively managing your list data.
Modifying lists isn’t just about adding and removing items. Often, we need to change the order of the items themselves. In Post #52, we will learn how to organize our data by sorting lists.
Author

Experienced Cloud & DevOps Engineer with hands-on experience in AWS, GCP, Terraform, Ansible, ELK, Docker, Git, GitLab, Python, PowerShell, Shell, and theoretical knowledge on Azure, Kubernetes & Jenkins. In my free time, I write blogs on ckdbtech.com