remove() is an inbuilt function in Python programming language that removes a given object from the list. It does not return any value.
obj - object to be removed from the list
The method does not return any value but removes the given object from the list.
Note:It removes the first occurrence of the object from the list.
[2, 1, 1, 4, 5] ['b', 'c', 'd']
It returns ValueError when the passed object is not present in the list
Traceback (most recent call last): File "/home/e35b642d8d5c06d24e9b31c7e7b9a7fa.py", line 8, in list2.remove('e') ValueError: list.remove(x): x not in list
Given a list, remove all the 1’s from the list and print the list.
[2, 3, 4, 4, 5]
- Python | Remove Duplicates from a List
- Python | Ways to remove duplicates from list
- Python | Ways to remove particular list element
- Python | Remove and print every third from list until it becomes empty
- Python | Remove empty tuples from a list
- Remove multiple elements from a list in Python
- List comprehension and ord() in Python to remove all characters other than alphabets
- List Methods in Python | Set 2 (del, remove(), sort(), insert(), pop(), extend()...)
- Python | Remove empty strings from list of strings
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Maximum sum of elements of list in a list of lists
- Python | Convert a nested list into a flat list
- Python List Comprehension | Segregate 0's and 1's in an array list
- Python | Remove items from Set
- Python | Sort the values of first list using second list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.