Latest web development tutorials

Python List index () method

Python list Python list


index () function is used to find the index position of the first occurrence of a value from the list.


index () method syntax:



  • obj - Find objects.

return value

This method returns the index position of the object to find, if not find the object is thrown.


The following example shows the index () function to use:


aList = [123, 'xyz', 'zara', 'abc'];

print "Index for xyz : ", aList.index( 'xyz' ) ;
print "Index for zara : ", aList.index( 'zara' ) ;

Examples of the above output results are as follows:

Index for xyz :  1
Index for zara :  2

Python list Python list