code
S = 'xxxabcxxxxabcxxabcxxabc' search="xxxa" last_cur=0 count=0 while(1): where=S.find(search) if(not where==-1): print(last_cur+where) S=S[where+len(search):] last_cur=last_cur+where+len(search) count+=1 else: break print("总数为:",count)
code
S = 'xxxabcxxxxabcxxabcxxabc' search="xxxa" last_cur=0 count=0 while(1): where=S.find(search) if(not where==-1): print(last_cur+where) S=S[where+len(search):] last_cur=last_cur+where+len(search) count+=1 else: break print("总数为:",count)