The index() function in Python helps to return the index of a given element in a list. We can also provide search starting and ending points through a list.
Index () parameter:
This method uses three parameters. The output of this method should be an integer value indicating the position of the element.
Index () return value
If the method finds multiple matches for a given element, it will only return the index of the first match.
|Input | Return Value | Element | Element Index | If there are no elements | Value Error exception|
Example of Index() method in Python
Example 1: How Index() works in Python
Output:
Example 2: If the searched element is not in the list, the index is ()
Output:
Example 3: Processing indexes by providing start and end parameters ()
Output: