展开全部
Python编程中对字符串进行搜索查找,并返回字符位e69da5e887aa62616964757a686964616f31333337396231置,案例代码如下:# multiple searches of a string for a substring
# using s.find(sub[ ,start[, end]])
#以下面test这段文本为例
text = 'MSKSASPKEPEQLRKLFIGGLSFETTDESLRSAHFESSSYGSAGRRF'
##查找上面文本中的SA字符串
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