面试题答案
一键面试import re
s = 'The dog runs fast. The cat jumps high.'
# 使用sub方法
new_s_sub = re.sub('The', 'A', s)
# 使用subn方法
new_s_subn, count = re.subn('The', 'A', s)
print("使用sub方法替换后的字符串:", new_s_sub)
print("使用subn方法替换后的字符串:", new_s_subn)
print("使用subn方法的替换次数:", count)