AlphaCodingSkills

Python - List index() Method


Advertisements

The Python list index() method is used to find out index number of first occurrence of a specified element in the list.

Syntax


list.index(elem)

Parameters

elem Required. value of the element which need to be searched in the list.

Example:

In the below example, list index() method is used to find out index number of first occurrence of an element called 'MAR' in the list called MyList

MyList = ['JAN', 'FEB', 'MAR', 'APR', 'MAR']

x = MyList.index('MAR') 
print(x)

Output

2

Lists Methods