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

What is index in Python

silencement
silencementOriginal
2019-05-18 11:40:1033415browse

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!

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