Home  >  Article  >  Backend Development  >  How to implement the contains function in python strings

How to implement the contains function in python strings

silencement
silencementOriginal
2019-05-23 17:44:4638883browse

How python strings implement the contains function: You can use the in method to implement the contains function, such as [if "blah" not in somestring: continue]. The contains function can also be implemented through the find function.

How to implement the contains function in python strings

Python's string object does not have a contains method. You do not need to use the string.contains method to determine whether it contains a substring, but Python has a simpler method to replace contains. function.

(Recommended tutorial: python video tutorial)

Method 1: Use the in method to implement the functions of contains:

How to implement the contains function in python strings

Method 2: Use the find function to implement the contains function

How to implement the contains function in python strings

The above is the detailed content of How to implement the contains function in python strings. 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