What does index mean in python

Release: 2019-07-06 13:11:41
Original
74592 people have browsed it

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)
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template