What is the difference between del, remove and pop on lists in python ?

When working with Python lists, you have three main methods to remove elements: remove(), del, and pop(). Each method serves different purposes and behaves differently depending on your needs.

Using remove()

The remove() method removes the first matching value from the list, not by index but by the actual value ?

numbers = [10, 20, 30, 40]
numbers.remove(30)
print(numbers)
[10, 20, 40]

If the value doesn't exist, remove() raises a ValueError ?

numbers = [10, 20, 30, 40]
try:
    numbers.remove(50)  # Value not in list
except ValueError as e:
    print(f"Error: {e}")
Error: list.remove(x): x not in list

Using del

The del statement removes an item at a specific index. It can also delete entire variables or slices ?

numbers = [10, 20, 30, 40, 55]
del numbers[1]  # Remove item at index 1
print(numbers)
[10, 30, 40, 55]

You can also delete multiple elements using slicing ?

numbers = [10, 20, 30, 40, 55]
del numbers[1:3]  # Remove items from index 1 to 2
print(numbers)
[10, 40, 55]

Using pop()

The pop() method removes an item at a specific index and returns the removed value. If no index is specified, it removes the last item ?

numbers = [100, 300, 400, 550]
removed_item = numbers.pop(1)  # Remove and return item at index 1
print(f"Removed: {removed_item}")
print(f"List: {numbers}")
Removed: 300
List: [100, 400, 550]

Using pop() without an index removes the last element ?

numbers = [100, 300, 400, 550]
last_item = numbers.pop()  # Remove and return last item
print(f"Removed: {last_item}")
print(f"List: {numbers}")
Removed: 550
List: [100, 300, 400]

Comparison

Method Removes By Returns Value? Best For
remove() Value No When you know the value to remove
del Index/Slice No When you know the position
pop() Index Yes When you need the removed value

Conclusion

Use remove() when you want to delete by value, del for deletion by index without return value, and pop() when you need both deletion and the removed value. Choose based on whether you know the value or index, and whether you need the removed item.

Updated on: 2026-03-25T06:01:59+05:30

652 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements