There is one other option in regular expression, the search
method
import re
string = 'Happy Birthday'
pattern = 'py'
print(re.search(pattern, string).span()) ## this prints starting and end indices
print(re.search(pattern, string).span()[0]) ## this does what you wanted
By the way, if you would like to find all the occurrence of a pattern, instead of just the first one, you can use finditer
method
import re
string = 'i think that that that that student wrote there is not that right'
pattern = 'that'
print([match.start() for match in re.finditer(pattern, string)])
which will print all the starting positions of the matches.