Last modified: May 30, 2026

Python List del: Remove Items Easily

Python lists are powerful. You can add, change, and remove items. One key tool is the del statement. It helps you delete items by position.

This guide covers Python list del. You will learn syntax, examples, and common mistakes. The article is simple and clear. Perfect for beginners.

What is del in Python?

The del statement is not a method. It is a Python keyword. It removes items from a list. It can also delete entire variables.

You use del with an index or a slice. It modifies the list in place. No new list is created.

Basic Syntax

The syntax is straightforward:


del list_name[index]

You can also delete a slice:


del list_name[start:stop]

Remember: del removes the item permanently. There is no undo.

Example 1: Remove a Single Item

Let's remove an item at index 2.


# Create a list
fruits = ["apple", "banana", "cherry", "date"]
print("Original:", fruits)

# Remove item at index 2 (cherry)
del fruits[2]
print("After del:", fruits)

Output:


Original: ['apple', 'banana', 'cherry', 'date']
After del: ['apple', 'banana', 'date']

The item "cherry" is gone. The list shrinks by one.

Example 2: Remove a Slice

You can delete multiple items at once. Use a slice.


# Create a list
numbers = [10, 20, 30, 40, 50]
print("Original:", numbers)

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

Output:


Original: [10, 20, 30, 40, 50]
After del slice: [10, 40, 50]

The slice [1:3] removes index 1 and 2. Items 20 and 30 are deleted.

Example 3: Delete Entire List

You can also delete the whole list variable.


# Create a list
colors = ["red", "green", "blue"]
print("Before:", colors)

# Delete the list
del colors

# This will cause an error
# print(colors)  # NameError: name 'colors' is not defined

After del colors, the variable no longer exists. Use this with caution.

Common Use Cases

Here are practical uses for del:

  • Removing unwanted items by index.
  • Clearing a slice of the list.
  • Deleting temporary data.

For example, you might remove the first or last item. Use del list[0] or del list[-1].

Difference Between del and pop()

Both remove items. But they differ:

  • del removes by index. It returns nothing.
  • pop() removes by index and returns the removed item.

Use pop() if you need the value. Use del if you only want to delete.

Difference Between del and remove()

The remove() method deletes by value. It finds the first match. The del statement deletes by index. Choose based on what you know.

If you know the value, use remove(). If you know the position, use del.

Using del with Negative Index

Negative indexes count from the end. -1 is the last item.


# Create a list
items = ["a", "b", "c", "d"]
print("Original:", items)

# Remove the last item
del items[-1]
print("After del -1:", items)

# Remove the second last item
del items[-2]
print("After del -2:", items)

Output:


Original: ['a', 'b', 'c', 'd']
After del -1: ['a', 'b', 'c']
After del -2: ['a', 'c']

This is handy for removing items from the end.

Common Mistakes

Watch out for these errors:

  1. Index out of range: If the index does not exist, Python raises IndexError.
  2. Deleting a variable that doesn't exist: This causes NameError.
  3. Forgetting that del modifies the list: The change is permanent.

Always check the list length before using del. You can use len() to be safe.

Performance Notes

The del statement is fast. Removing an item from the end is O(1). Removing from the beginning is O(n) because items shift.

For large lists, removing from the end is better. If you must remove from the start often, consider using a deque from the collections module.

Related Concepts

You can also remove items by index using other methods. For a deeper look, read our guide on Python List Remove by Index.

If you want to add items, see Python List Append to End for appending or Python List Insert: Complete Guide for inserting.

Complete Example

Here is a full example with comments:


# Start with a list of numbers
data = [1, 2, 3, 4, 5, 6]
print("Start:", data)

# Remove the first item
del data[0]
print("After removing first:", data)

# Remove items from index 1 to 3
del data[1:3]
print("After removing slice:", data)

# Remove the last item
del data[-1]
print("After removing last:", data)

# Check the final list
print("Final list:", data)

Output:


Start: [1, 2, 3, 4, 5, 6]
After removing first: [2, 3, 4, 5, 6]
After removing slice: [2, 5, 6]
After removing last: [2, 5]
Final list: [2, 5]

When to Use del

Use del when:

  • You know the index of the item.
  • You want to delete a slice.
  • You don't need the removed value.
  • You want to delete the whole list.

It is a simple and direct tool.

Conclusion

The del statement is a key part of Python list management. It removes items by index or slice. It is fast and easy to use.

Remember the syntax: del list[index]. Practice with examples. Avoid common mistakes like index errors.

Use del when you need to delete without returning a value. For other cases, explore pop() or remove().

Now you know how to use Python list del. Start coding and manage your lists with confidence.