Home > Article > Backend Development > What is index in Python
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.
The following uses several examples to illustrate the usage of the index() method. The operation is as follows:
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
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!