What is the list remove() function in Python?

The remove() method is a built-in method in Python that removes a specified element in a list. If the specified element is present more than once, its first occurrence is removed from the list.

Syntax

The syntax of the remove() method is as follows.

list.remove(element)

Parameters and return value

This method takes one necessary parameter that needs to be removed from the list.

The remove() method does not return a value. However, if the specified element is not present in a list, it gives a value error.

Code

In the code below, the element e is removed from the list vowels. In the next attempt to remove s from the list, the function gives a value error because s is not present in the vowels list.

# vowels list
vowels = ['a', 'e', 'i', 'o', 'u']
# 'e' is removed by remove() funtion
vowels.remove('e')
# Updated vowels List
print('Vowels list: ', vowels)
# 's' ihas to be removed from vowels: Value error
vowels.remove('s')
print('Error Vowels list: ', vowels)

In the number list, 6 is present twice and the remove() function removes its first instance.

# number list
number = [1, 2, 3, 6, 4, 5, 6]
# '6' is removed by remove() funtion
number.remove(6)
# Updated number List
print('Number list: ', number)
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources