ld.I am not a businessman." x= x.replace('i ','I ')x= x.replace(' i ','I ') print(x) 2 )使用正则表达式 x= "i am a teacher,i am man, and i am 38 years old.I am not a businessman." import re pattern = pile(r'(?:[^\w]|\b)i(?:[^\w])') while True: result = pattern.search(x) if result: if result.start(0) != 0: x= x[:result.start(0)+1]+'I'+x[result.end(0)-1:] else: x= x[:result.start(0)]+'I'+x[result.end(0)-1:] else: break print(x) 4.2 假设有一段英文,其中有单词中间的字母“i”误写为“I”,请编写程序进行纠正。答:这里给出 Python 3.4.2 代码,如果使用 Python 2.7.8 的话只需要修改其中的 print() 函数为 print 语句即可。 import rex= "I am a teacher,I am man, and I am 38 years old.I am not a busInessman." print(x) pattern = pile(r'(?:[\w])I(?:[\w])') while True: result = pattern.search(x) if result: if result.start(0) != 0: x= x[:result.start(0)+1]+'i'+x[result.end(0)-1:] else: