Latest web development tutorials

Python3 List index () method

Python3 list Python3 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/python3

list1 = ['Google', 'w3big', 'Taobao']
print ('w3big 索引值为', list1.index('w3big'))
print ('Taobao 索引值为', list1.index('Taobao'))

Examples of the above output results are as follows:

w3big 索引值为 1
Taobao 索引值为 2

Python3 list Python3 list