How do I check if a given Python string is a substring of another one?


Question

I have two strings and I would like to check whether the first is a substring of the other. Does Python have such a built-in functionality?

1
280
2/28/2011 3:13:10 PM

Accepted Answer

Try using in like this:

>>> x = 'hello'
>>> y = 'll'
>>> y in x
True
459
2/28/2011 3:14:24 PM

Try

isSubstring = first in theOther

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon