list.remove()

list.remove(x)
Returns: None · Updated March 14, 2026 · List Methods
lists methods mutation

The .remove() method removes the first occurrence of a specified value from a list. If the value exists multiple times, only the first one is removed. If the value is not found, a ValueError is raised. This method modifies the list in place and returns None.

Syntax

list.remove(x)

Parameters

ParameterTypeDescription
xanyThe value to remove from the list. Can be of any type that exists in the list.

Return Value

Returns None. The method modifies the list in place.

Examples

Basic usage - removing a value

Remove the first occurrence of a value:

fruits = ["apple", "banana", "cherry", "banana"]
fruits.remove("banana")
print(fruits)
# ['apple', 'cherry', 'banana']

Only the first “banana” is removed. The second one remains.

Removing a string value

colors = ["red", "green", "blue"]
colors.remove("green")
print(colors)
# ['red', 'blue']

Removing a number from a list

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

What happens when value is not found

Attempting to remove a non-existent value raises ValueError:

items = ["a", "b", "c"]
# items.remove("d")
# ValueError: list.remove(x): x not in list

Safe pattern with try/except

Wrap .remove() in try/except to handle missing values gracefully:

def safe_remove(lst, value):
    try:
        lst.remove(value)
        return True
    except ValueError:
        return False

numbers = [1, 2, 3, 4, 5]
removed = safe_remove(numbers, 3)
print(f"Removed: {removed}, List: {numbers}")

removed = safe_remove(numbers, 99)
print(f"Removed: {removed}, List: {numbers}")

Common Patterns

Removing by value vs by index

Use .remove(x) when you know the value but not its position. Use .pop(i) when you know the index:

inventory = ["sword", "shield", "potion", "armor"]
inventory.remove("potion")
last_item = inventory.pop()
print(inventory)
print(last_item)

Removing during iteration

Never modify a list while iterating with a for loop. Use a list copy or comprehension:

# Wrong - modifies during iteration causes issues

# Correct approach - filter with comprehension
items = [1, 2, 3, 4, 5, 6]
items = [x for x in items if x % 2 != 0]
print(items)

# Alternative: use while loop with index
numbers = [1, 2, 3, 4, 5]
i = 0
while i < len(numbers):
    if numbers[i] % 2 == 0:
        numbers.remove(numbers[i])
    else:
        i += 1
print(numbers)

Removing all occurrences

Since .remove() only removes the first match, use a while loop to remove all:

letters = ["a", "b", "a", "c", "a"]
while "a" in letters:
    letters.remove("a")
print(letters)

letters = ["a", "b", "a", "c", "a"]
letters = [x for x in letters if x != "a"]
print(letters)

Performance Note

  • .remove() performs a linear scan - O(n) time complexity
  • Best case is O(1) when element is at the start
  • Worst case is O(n) when element is at the end or not present
  • For frequent removals, consider collections.deque

See Also