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?
3 Answers
Try using in like this:
>>> x = 'hello'
>>> y = 'll'
>>> y in x
True
1 Comment
Piyush S. Wanare
What about complexity as compare to using regex?
string.find("substring") will help you. This function returns -1 when there is no substring.
2 Comments
Musixauce3000
What if I was looking for the position of the third or fourth occurrence of 'e', or the likes thereof?
Cutton Eye
python supports regulary expressions (regex). What ever you are looking for make a regex-group auto of it, afterwards you can select the 3rd group.