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?
            Asked
            
        
        
            Active
            
        
            Viewed 4.6e+01k times
        
    3 Answers
513
            Try using in like this:
>>> x = 'hello'
>>> y = 'll'
>>> y in x
True
 
    
    
        Andrew Hare
        
- 344,730
- 71
- 640
- 635
43
            
            
        string.find("substring") will help you. This function returns -1 when there is no substring.
 
    
    
        cs95
        
- 379,657
- 97
- 704
- 746
 
    
    
        Daniel Wehner
        
- 2,159
- 1
- 18
- 22
- 
                    What if I was looking for the position of the third or fourth occurrence of 'e', or the likes thereof? – Musixauce3000 Apr 14 '16 at 22:37
- 
                    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. – Cutton Eye Feb 08 '18 at 15:35
 
    