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

snakile picture snakile · Feb 28, 2011 · Viewed 427.1k times · Source

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?

Answer

Andrew Hare picture Andrew Hare · Feb 28, 2011

Try using in like this:

>>> x = 'hello'
>>> y = 'll'
>>> y in x
True