October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Remove an Element from a List in Python

Use remove() for the first matching value, pop() or del for an index, and a list comprehension to remove all matches or filter items.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use my_list.remove(value) to remove the first matching value. To remove an item by position, use my_list.pop(index) if you need the removed item, or del my_list[index] if you do not. To remove every match or filter by a condition, build a new list with a comprehension.

Choose the right way to remove a list item

Goal Use What happens Possible error
Remove the first item equal to a value items.remove(value) Changes the existing list; returns None. ValueError if no equal item exists.
Remove an item by index and keep it removed = items.pop(index) Changes the existing list and returns the removed item. IndexError if the list is empty or the index is out of range.
Remove an item by index without keeping it del items[index] Changes the existing list; does not return the removed item. IndexError if the index is out of range.
Remove every matching value or apply a condition [item for item in items if item != value] Creates a new list and preserves the order of retained items. No missing-value error; items that fail the condition are simply excluded.

Remove an item by value with remove()

Call remove(value) when you know what the item is but not its position. Python removes only the first item equal to that value.

fruits = ["apple", "banana", "apple"]
fruits.remove("apple")

print(fruits)  # ['banana', 'apple']

If the value might not be present, check first or handle the exception:

if "pear" in fruits:
    fruits.remove("pear")

remove() modifies the list in place and returns None. Do not assign its result back to the list:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# Incorrect: items becomes None
items = items.remove("banana")

Remove an item by index with pop() or del

Use pop() when you need the removed item

pop(index) removes and returns the item at that position. Python list indexes start at zero, so index 1 refers to the second item. If you omit the index, pop() removes and returns the last item.

colors = ["red", "green", "blue"]
removed = colors.pop(1)

print(removed)  # green
print(colors)   # ['red', 'blue']

An empty list or an invalid index raises IndexError. Check the list or handle the exception when either case is possible.

Use del when you only need to delete

del removes an item by index without returning it. It can also remove a range using slice notation:

numbers = [10, 20, 30, 40]
del numbers[1]      # removes 20
del numbers[1:3]    # removes 30 and 40

To empty the existing list while keeping the same list object, use del items[:]. To clear all its items directly, use items.clear().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remove all matching values or filter by a condition

remove() stops after the first equal value. To remove every occurrence, create a filtered list instead:

items = ["pen", "notebook", "pen", "ruler"]
items = [item for item in items if item != "pen"]

print(items)  # ['notebook', 'ruler']

This comprehension creates a new list and keeps the relative order of items that pass the test. The same pattern works for a condition; for example, keep only positive numbers:

numbers = [-3, 0, 4, -1, 7]
positive = [number for number in numbers if number > 0]

print(positive)  # [4, 7]
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Avoid removing items while iterating over the same list

Removing items as you move forward through that same list can shift later items into positions the iteration has already passed. As a result, an item that also meets the removal condition may be skipped. When you want to examine every item, a filtered list comprehension is often simpler and safer than modifying the list during iteration.

These behaviors are documented in the Python 3.14.8 data structures tutorial.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.