logo

Python List Index() Method


Show

Description

Python list method index() returns the lowest index in the list that obj appears.

Syntax

Following is the syntax for index() method -

list.index(obj)

Parameters

  • obj - This is the object to find out.

Return Value

This method returns the index of the found object otherwise raises an exception indicating that value does not find.

Example

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.