# multiple searches of a string for a substring |
# using s.find(sub[ ,start[, end]]) |
|
text = 'MSKSASPKEPEQLRKLFIGGLSFETTDESLRSAHFESSSYGSAGRRF' |
|
search = 'SA' |
start = 0 |
while True : |
index = text.find(search, start) |
# if search string not found, find() returns -1 |
# search is complete, break out of the while loop |
if index = = - 1 : |
break |
print ( "%s found at index %d" % (search, index) ) |
# move to next possible start position |
start = index + 1 |
//结果:
SA found at index 3
SA found at index 31
SA found at index 41