Last modified: May 30, 2026

Python List Remove by Index

Removing an element from a Python list by its index is a common task. You need to know the position of the item. Python gives you two main ways to do this: the pop() method and the del statement.

Both methods work on the index. But they behave differently. Understanding the difference is key to writing clean code.

This guide will show you how to use both. You will see simple examples and code outputs. By the end, you will know exactly which method to choose.

Why Remove by Index?

Lists store items in order. Each item has an index starting from 0. Sometimes you need to remove a specific item based on its position.

For example, you might have a list of scores. You want to remove the first score. Or the last score. Or the third score.

Removing by value is different. That removes the first occurrence of an item. But when you know the position, index removal is faster and more precise.

Using pop() to Remove by Index

The pop() method removes an item at a given index. It also returns the removed item. This is useful when you need the value later.

If you do not provide an index, pop() removes the last item by default.

Here is an example:

# Create a list of fruits
fruits = ["apple", "banana", "cherry", "date"]

# Remove the item at index 1 (banana)
removed_fruit = fruits.pop(1)

print("Removed fruit:", removed_fruit)
print("Updated list:", fruits)

Output:

Removed fruit: banana
Updated list: ['apple', 'cherry', 'date']

Notice that pop(1) removed "banana" and stored it in removed_fruit. The list now has three items.

You can also use negative indices. Index -1 removes the last item.

# Remove the last item using index -1
last_fruit = fruits.pop(-1)
print("Last fruit removed:", last_fruit)
print("List after pop(-1):", fruits)

Output:

Last fruit removed: date
Updated list: ['apple', 'cherry']

pop() is great when you need the removed value. It is also safe because it raises an IndexError if the index is out of range.

Using del to Remove by Index

The del statement removes an item at a specific index. It does not return the removed item. Use del when you only want to delete the item.

Here is an example:

# Create a list of numbers
numbers = [10, 20, 30, 40, 50]

# Remove the item at index 2 (30)
del numbers[2]

print("List after del:", numbers)

Output:

List after del: [10, 20, 40, 50]

You can also use del to remove a slice of items. For example, remove items from index 1 to 3.

# Remove items from index 1 to 3 (not including 3)
del numbers[1:3]
print("List after slice removal:", numbers)

Output:

List after slice removal: [10, 50]

del is faster than pop() because it does not return a value. Use it when you only need to delete.

Choosing Between pop() and del

Here is a simple rule:

  • Use pop() when you need the removed item.
  • Use del when you only want to remove the item.

Both methods are efficient. They have a time complexity of O(n) because shifting elements is required.

If you need to remove multiple items by index, consider using a list comprehension or a loop. For example, you can build a new list excluding certain indices.

For more list operations, check out Python List Append to End or Python List Insert: Complete Guide.

Error Handling

Both pop() and del raise an IndexError if the index is out of range. Always check the list length before removing.

You can use len() to verify the index is valid. See Python List Length Check with If for more details.

Here is a safe example:

# Safe removal with index check
my_list = [1, 2, 3, 4]
index_to_remove = 5

if 0 <= index_to_remove < len(my_list):
    removed = my_list.pop(index_to_remove)
    print("Removed:", removed)
else:
    print("Index out of range")

Output:

Index out of range

This pattern prevents crashes in your code.

Removing All Items by Index

If you want to remove all items from a list, you can use a loop. But it is easier to use clear() or reassign an empty list.

To remove items one by one from the end, use a loop with pop().

# Remove all items from the end
while my_list:
    print("Removing:", my_list.pop())

This removes items in reverse order.

Conclusion

Removing an item by index in Python is easy. Use pop() when you need the value. Use del when you only want to delete.

Always check the index to avoid errors. Both methods are reliable and widely used.

Practice with small examples. Soon you will master list removal by index.