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 index() - GeeksforGeeks Python List index() - Find Index of ItemLast Updated : 17 Jul, 2026 index() method is used to find the position of an element in a list. It searches the list from left to right and returns the index of the first matching occurrence. If the element is not found, it raises a ValueError. Example: In this example, index() is used to find the position of an element in a list.
Output 1 Explanation: a.index("dog") searches for "dog" in the list and element is found at index 1, so 1 is returned. Syntax
Parameters:
Return Value: Returns the index of the first matching occurrence and raises ValueError if the element is not found. ExamplesExample 1: In this example, the search is limited to a specific portion of the list using the start and end parameters.
Output 5 Explanation: a.index(40, 4, 8) searches for 40 between indices 4 and 7 and first matching value in that range is found at index 5. Example 2: In this example, the target element appears multiple times. The index() method returns the position of the first occurrence only.
Output 1 Explanation: a.index("blue") returns the index of the first occurrence of "blue" and later occurrences are ignored. Example 3: In this example, index() is used with a list containing tuple elements.
Output 1 Explanation: a.index(("Lucas", 22)) searches for the exact tuple ("Lucas", 22) and tuple is found at index 1. 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. |