[Fixed] Does Python have a string ‘contains’ substring method?

Question (Issue)

I’m looking for a string.contains or string.indexof method in Python.

I want to do:

if not somestring.contains("blah"):
   continue

Now we will see Solution for issue: Does Python have a string ‘contains’ substring method?


Answer (solution)

Use the in operator:

if "blah" not in somestring: 
    continue

This question is answered By – Michael Mrozek

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0