Find the substring from left to right, if it exists, output the index value of the first character of the substring, if it does not exist, output -1
# find()a = 'love you'b = 'you'c = 'no'print(a.find(b)) #5print(a.find(c)) #-1
Find the substring from left to right, if it exists, output the index value of the first character of the substring, if it does not exist, output -1
# rfind()a = 'love you'b = 'you'c = 'no'print(a.rfind(b)) #5print(a.rfind(c)) #-1
Count the number of substrings in the parent string
# count()a = 'love you do you love me'b = 'you'c = 'no'print(a.count(b)) #2print(a.count(c)) #0
Find all the positions where the specified string contains substrings and return it as a list
def indexstr(str1,str2):'''Find all positions where the specified string str1 contains the specified substring str2, and return ''' in the form of a listlenth2=len(str2)lenth1=len(str1)indexstr2=[]i=0while str2 in str1[i:]:indextmp = str1.index(str2, i, lenth1)indexstr2.append(indextmp)i = (indextmp + length2)return indexstr2