The Python Oracle

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

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Melt

--

Chapters
00:00 How Do I Check If A Given Python String Is A Substring Of Another One?
00:17 Answer 1 Score 56
00:24 Accepted Answer Score 516
00:34 Answer 3 Score 43
00:44 Thank you

--

Full question
https://stackoverflow.com/questions/5143...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #string #substring

#avk47



ACCEPTED ANSWER

Score 516


Try using in like this:

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



ANSWER 2

Score 56


Try

isSubstring = first in theOther



ANSWER 3

Score 43


string.find("substring") will help you. This function returns -1 when there is no substring.