Latest web development tutorials

Python List index () method

Python list Python list


description

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

grammar

index () method syntax:

list.index(obj)

parameter

  • obj - Find objects.

return value

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

Examples

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

#!/usr/bin/python

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