a = "Hello how are you"
b ="how"
我想在a中搜索b,结果将显示a中b的开始索引和结束索引。答案:
start_index = 7 end_index = 9
任何人都可以帮助我。
start_index = a.find(b) + 1
end_index = a.find(b) + len(b)
span
:import re
substring = re.search(b,a)
start, end = substring.span()
import re
a = "Hello how are you"
b ="how"
start_index, end_index = re.search(b, a).span()
print(start_index, end_index)