查询字符串部分字符索引,并返回索引成一个元组形式
递归在字符串中的应用
list1 = []
def findall(str, s):
# find()方法没找到返回-1
a = str.find(s, 0, len(str))
if a == 0:
list1.append(a)
elif a > 0:
list1.append(list1[-1] + a + len(s))
else:
print('没找到')
if s in str[a + len(s):len(str)]:
findall(str[a + len(s):len(str)], s)
return tuple(list1)
str1 = "helloworldhellopythonhelloc++hellojava"
print(findall(str1, 'hello'))