HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCritical

Does Python have a string 'contains' substring method?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
havepythoncontainsdoesmethodsubstringstring

Problem

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

I want to do:

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

Solution

Use the in operator:

if "blah" not in somestring: 
    continue


Note: This is case-sensitive.

Code Snippets

if "blah" not in somestring: 
    continue

Context

Stack Overflow Q#3437059, score: 8670

Revisions (0)

No revisions yet.