The find() method returns the index of first occurrence of the substring (if found). If not found, it returns -1.
#!/usr/bin/python3 # -*- coding: UTF-8 -*- str = "Associate professor in computer science and also a joint professor in information science" # From the beginning, found the 1st occurrence print (str.find('professor')) # For the index of 30 and after, found the 2nd occurrence print (str.find('professor', 30)) # For the index of 60 and after, not found and return -1 print (str.find('professor', 60))
10 57 -1
str.find(substr[, start[, end]] )
|substr||The substring to be searched in the string|
It returns the index if found and -1 otherwise.