Does Python have a string 'contains' substring method?

Blankman picture Blankman · Aug 9, 2010 · Viewed 4.4M times · Source

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

I want to do:

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

Answer

Michael Mrozek picture Michael Mrozek · Aug 9, 2010

You can use the in operator:

if "blah" not in somestring: 
    continue