1. Overview
Many times we need to find an element in the list and output the corresponding index value; this time we need to use the index() method .
2. Index() method
2.1 Description
The index() function is used to find the index position of the first matching item of a certain value from the list.
2.2 Usage
list.index(obj)
Comments:
obj——The object to be found.
Return value:
This method returns the index position of the search object, and throws an exception if the object is not found.
Example:
A = [123, 'xyz', 'zara', 'abc'] print(A.index('xyz')) # 结果 1 print(A.index('zzz')) # 报错 :ValueError: 'zzz' is not in list
Run result:
##For more Python related technical articles, please visitPython tutorial column for learning!
The above is the detailed content of What does index mean in python. For more information, please follow other related articles on the PHP Chinese website!