How to Remove an Item from a List in Python with pop
list.pop() removes an item from a list and hands it back, so you can use what you took out. With no argument it takes the last item, which also makes it the way to undo the latest append(). This guide shows both forms and the error on an empty list, with real output from Python 3.15.2.
Syntax
<item> = <list>.pop()
<item> = <list>.pop(<index>)
| Part | What it means |
|---|---|
<list>.pop() | Removes and returns the last item |
<list>.pop(<index>) | Removes and returns the item at that position; 0 is the first |
<item> = ... | Optional: keep the removed item. The list changes either way |
Python's tutorial: "Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. It raises an IndexError if the list is empty or the index is outside the list range."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
queue = ["first", "second", "third"]
last = queue.pop()
print(last)
print(queue)
first = queue.pop(0)
print(first)
print(queue)

Step 2: Run It
uv run python pop_items.py
third
['first', 'second']
first
['second']
![The output in a terminal: third, then ['first', 'second'], then first, then ['second'].](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/python-pop-02-output.webp)
pop() returned "third" and the list shrank to two items; pop(0) returned "first" and left one.
Popping an Empty List
empty = []
empty.pop()
uv run python pop_empty.py
Traceback (most recent call last):
File "/Users/you/source/python-basics/pop_empty.py", line 2, in <module>
empty.pop()
~~~~~~~~~^^
IndexError: pop from empty list
Check that the list isn't empty first, for example with if empty:.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Popping an empty list | IndexError: pop from empty list | Check the list first |
Popping a position the list doesn't have, as in [1].pop(5) | IndexError: pop index out of range | Use an index between 0 and len(list) - 1 |
Expecting pop() to take the first item | It takes the last one | Use pop(0) for the first |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A later loop misses items | The list was popped while a for loop was walking through it | Loop over a copy, or build a new list |
FAQ
What's the difference between pop() and remove()?
pop() removes by position and returns the item. remove() removes the first item equal to a value you give and returns nothing.
Can I undo an append() with it?
Yes. append() adds at the end, and pop() removes from the end.
Conclusion
queue.pop() took "third" off the end, queue.pop(0) took "first" off the front, both handed the item back, and an empty list raised IndexError: pop from empty list.
Additional Resources
- More on lists —
pop()and the other list methods.
