GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python List remove() Method - GeeksforGeeks Python List remove() MethodLast Updated : 17 Jul, 2026 remove() method is used to remove the first occurrence of a specified element from a list. It modifies the original list directly and does not create a new list. If the specified element is not found, a ValueError is raised. Example: In this example, remove() is used to remove an element from a list.
Output ['apple', 'orange'] Explanation: a.remove("banana") removes the first occurrence of "banana" from the list. The original list is updated directly. Syntax
ExamplesExample 1: In this example, a value is removed from a list using remove(). The method searches for the specified element and removes its first occurrence.
Output [10, 20, 40] Explanation: a.remove(30) removes 30 from the list. Example 2: Here, the same value appears multiple times in the list. The remove() method removes only the first matching occurrence.
Output [10, 5, 15, 5] Explanation: a.remove(5) removes only the first occurrence of 5. The remaining occurrences stay unchanged. Example 3: In this example, we check whether an element exists before removing it. This prevents a ValueError from occurring.
Output ['red', 'green'] Explanation:
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |