Python List pop() Method

list.pop() removes an item from a list and returns it.

This method is useful when you want to both:

  • delete an item from a list
  • keep the removed value for later use

If you do not pass an index, pop() removes the last item. Beginners often confuse pop() with remove(), or expect it to create a new list instead of changing the original one.

Quick example

numbers = [10, 20, 30]
last_item = numbers.pop()

print(last_item)
print(numbers)

Output:

30
[10, 20]

Use pop() to remove and return an item from a list. With no argument, it removes the last item.

What pop() does

pop() has two main jobs:

  • It removes one item from a list
  • It returns the item that was removed

Important details:

  • If no index is given, it removes the last item
  • It changes the original list
  • It does not create a new list

Example:

colors = ["red", "green", "blue"]

removed = colors.pop()

print(removed)
print(colors)

Output:

blue
['red', 'green']

Basic syntax

list.pop([index])

The index is optional.

  • If you do not give an index, pop() removes the last item
  • If you give an index, pop() removes the item at that position
  • You can store the result in a variable

Example:

letters = ["a", "b", "c"]

item = letters.pop(1)

print(item)
print(letters)

Output:

b
['a', 'c']

If you are new to list positions, see Python lists explained for beginners.

Using pop() without an index

When you call pop() with no argument, Python removes the last item in the list.

tasks = ["write", "test", "submit"]

last_task = tasks.pop()

print(last_task)
print(tasks)

Output:

submit
['write', 'test']

This is useful when using a list like a stack, where the last item added is the first item removed.

Using pop() with an index

You can pass an integer index to remove an item at a specific position.

fruits = ["apple", "banana", "cherry", "orange"]

removed = fruits.pop(1)

print(removed)
print(fruits)

Output:

banana
['apple', 'cherry', 'orange']

You can also use negative indexes:

fruits = ["apple", "banana", "cherry"]

removed = fruits.pop(-1)

print(removed)
print(fruits)

Output:

cherry
['apple', 'banana']

Negative indexes count from the end of the list. So -1 means the last item.

If you need to find a position before removing it, see the list.index() method.

What pop() returns

pop() returns the item that was removed.

This is one of the biggest differences between pop() and remove().

Example:

names = ["Ana", "Ben", "Cara"]

removed_name = names.pop(0)

print(removed_name)
print(names)

Output:

Ana
['Ben', 'Cara']

This is useful when you need the removed value after taking it out of the list.

By comparison, remove() deletes by value and returns None.

Common errors and edge cases

Popping from an empty list

If the list is empty, pop() raises an IndexError.

items = []
items.pop()

Output:

IndexError: pop from empty list

Fix:

  • Check that the list is not empty before calling pop()
  • Or handle the error with try and except

Example:

items = []

if items:
    print(items.pop())
else:
    print("The list is empty.")

Using an index that does not exist

If the index is outside the valid range, Python raises an IndexError.

numbers = [10, 20, 30]
numbers.pop(5)

Output:

IndexError: pop index out of range

Fix:

  • Check the list length with len()
  • Make sure the index is valid before removing
numbers = [10, 20, 30]
index = 2

if 0 <= index < len(numbers):
    print(numbers.pop(index))
else:
    print("Index is out of range.")

For more help with this kind of problem, see IndexError: list index out of range.

Passing a non-integer index

pop() expects an integer index.

numbers = [10, 20, 30]
numbers.pop("1")

Output:

TypeError: 'str' object cannot be interpreted as an integer

Fix:

  • Pass an integer such as 0, 1, or -1
  • If the value comes from input, convert it first
numbers = [10, 20, 30]
index = int("1")

print(numbers.pop(index))
print(numbers)

Output:

20
[10, 30]

pop() vs remove()

These methods are similar, but they are not the same.

Use pop() when:

  • you want to remove by index
  • you want the removed item returned
  • you want to remove the last item by default

Use remove() when:

  • you want to remove by value
  • you know the item itself, not its position

Compare these examples:

numbers = [10, 20, 30, 20]

removed = numbers.pop(1)
print(removed)
print(numbers)

Output:

20
[10, 30, 20]
numbers = [10, 20, 30, 20]

numbers.remove(20)
print(numbers)

Output:

[10, 30, 20]

In the first example, pop(1) removes the item at index 1.

In the second example, remove(20) removes the first matching value 20.

If your goal is practical list cleanup, see how to remove an item from a list in Python.

Common mistakes

Beginners often run into these problems with pop():

  • Trying to pop from an empty list
  • Using an index larger than the list length
  • Confusing pop() with remove()
  • Expecting pop() to return a new list
  • Passing a string instead of an integer index

Helpful checks while debugging:

print(my_list)
print(len(my_list))
print(my_list.pop())
print(my_list.pop(0))
print(type(index))

Be careful with these debugging lines:

  • print(my_list.pop()) changes the list
  • print(my_list.pop(0)) also changes the list

If you only want to inspect the list, use print(my_list) first.

FAQ

Does pop() remove the last item by default?

Yes. If you do not pass an index, pop() removes and returns the last item.

What is the difference between pop() and remove()?

pop() removes by index and returns the removed item. remove() removes by value and returns None.

Can pop() use negative indexes?

Yes. For example, pop(-1) removes the last item.

What happens if the list is empty?

Python raises IndexError because there is no item to remove.

See also