Does Python have a string 'contains' substring method?

Submitted 4 years, 8 months ago
Ticket #207
Views 349
Language/Framework Python
Priority Low
Status Closed

looking for a string.contains or string.indexof method in Python.

want to do:

if not somestring.contains("blah"):
   continue
Submitted on Oct 04, 20
add a comment

2 Answers

Verified

In [1]: s = 'python'

In [2]: s.startswith('pyt')
Out[2]: True

In [3]: s.find('ho')
Out[3]: 3

Submitted 4 years, 8 months ago

AsYou can use the in operator:

if "blah" not in somestring: 
    continue

Submitted 4 years, 8 months ago


Latest Blogs