Fix Python – How do I check if a given Python string is a substring of another one? [duplicate]

Question

Asked By – snakile

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?

Now we will see solution for issue: How do I check if a given Python string is a substring of another one? [duplicate]


Answer

Try using in like this:

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

This question is answered By – Andrew Hare

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0