Python读取文本文件后replace() 替换不全的问题

今天碰到一个奇怪的事情,用Sublime Text读取 一个有3行包含‘Python’字样的文本文件,并用for遍历后,在使用replace()将‘Python’替换为‘Java’字样时,发现最后一行没有变化,大家帮忙看下到底怎么回事,谢谢。

源文本:
In Python you can do whatever you want to.
In Python you can go as far as you can.
In Pyhton you can fly in high!

代码:

learning_python='learning_python.txt'
with open(learning_python) as file_object:
    for i in file_object:
        i=i.strip()
        print(i.replace('Python','Java'))

运行结果:
In Java you can do whatever you want to.
In Java you can go as far as you can.
In Pyhton you can fly in high!

想要的结果:
In Java you can do whatever you want to.
In Java you can go as far as you can.
In Java you can fly in high!

你第三行的Python 写成了 Pyhton
Python 中 t 和h 写反了

img

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

因为你最后一行的python拼错了

img

有帮助望采纳~

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632