面试题答案
一键面试import re
s = 'hello world, hello python'
# 使用findall方法
result_findall = []
for match in re.finditer('hello', s):
result_findall.append(match.start())
print("findall方法结果:", result_findall)
# 使用finditer方法
result_finditer = []
for match in re.finditer('hello', s):
result_finditer.append(match.start())
print("finditer方法结果:", result_finditer)