Home >Backend Development >Python Tutorial >What does index mean in python

What does index mean in python

尚
Original
2019-07-06 13:11:4174655browse

What does index mean in python

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:

What does index mean in python

##For more Python related technical articles, please visit

Python 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn