Python list method index() returns the lowest index in the list that obj appears.
Following is the syntax for index() method -
This method returns the index of the found object otherwise raises an exception indicating that value does not find.
The following example shows the usage of index() method.
#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc']; print "Index for xyz : ", aList.index( 'xyz' ) print "Index for zara : ", aList.index( 'zara' )
When we run the above program, it produces the following result -
Index for xyz : 1 Index for zara : 2
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.