How do I find the index of an item in a Python list?

To find the index of an element in a Python list, you can use the list.index(element, start, end) method. The list.index() method takes an element as an argument and returns the index of only the first occurrence of the matching element. If the element is not found, a ValueError exception will be thrown. The optional "start" and "end" arguments are used to restrict the search to a specific subsequence of the list. If an input element is found in the list between the specified indices, the method returns the element's index where it occurs first. In Python, list indexes start at 0. In this Python example, we return the index of a list item using the list.index() method. Click Execute to run Python List Index Example online and see the result.
Loading...