Home > Backend Development > Python Tutorial > What is index in Python

What is index in Python

silencement
Release: 2019-05-22 14:00:29
Original
33478 people have browsed it

In the python language, if you want to know whether a string is included in the list, you can directly use the index method to determine. If it is included in the string, it will return the position where the string first appears; if it is not included, an error will occur. Today we will talk about the index() method in Python.

What is index in Python

The following uses several examples to illustrate the usage of the index() method. The operation is as follows:

What is index in Python

As can be seen from the above output results, Python returned a string' The position of on' in str_1. In Python, indexing is zero-based.

Let’s look at another example

What is index in Python

You can read the book, str_4 is not in str_3, so Python will report an error.

The above is the detailed content of What is index in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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