Python Finding the Index of a List Item



The index() method of list class returns the index of first occurrence of the given item.

Syntax

list.index(obj)

Return value

The index() method returns an integer, representing the index of the first occurrence of the object.

Example

Take a look at the following example −

lst = [25, 12, 10, -21, 10, 100]
print ("lst:", lst)
x = lst.index(10)
print ("First index of 10:", x)

It will produce the following output

lst: [25, 12, 10, -21, 10, 100]
First index of 10: 2
python_list_methods.htm
Advertisements