37,720
社区成员
发帖
与我相关
我的任务
分享
s = 'hello world hello man hello women'
t = 'hello'
#标记是否有子串
flag = 0
#标记位置
pos = -1
#循环切片用
s1 = s
#找到最后一个匹配字符串的位置pos,切片pos+1后的字符串
while s1.find(t)!=-1:
pos = s1.find(t)
s1 = s1[pos+1:]
flag = 1
#s-(s1+1)既为位置
if pos != -1:
print(len(s)-len(s1)-1)
else:
print(-1)