从txt文件中读取两行文字,然后用replace()把其中的Python替换为Java,但是没有起作用。
这是txt文件:
In Python you can deal with data.
In Python you can get some Internet data.
这是程序:
with open('learning_python.txt') as file_object:
for line in file_object:
line.replace('Python', 'Java')
print(line)
理想输出:
In Java you can deal with data.
In Java you can get some Internet data.
实际输出:
In Python you can deal with data.
In Python you can get some Internet data.
希望大家帮帮忙。