10-1
print("First time:")
with open("learning_python.txt") as file_object:
contents=file_object.read()
print(contents)
print("Second time:")
with open("learning_python.txt") as file_object:
for line in file_object:
print(line.rstrip())
print("Third time:")
with open("learning_python.txt") as file_object:
lines=file_object.readlines()
content=''
for line in lines:
content=content+line
print(content)
10-2
with open("learning_python.txt") as file_object:
lines=file_object.readlines()
content=''
for line in lines:
content=content+line
print(content)
print(content.replace("python","java"))
10-3
name=input("Please input your name:")
with open("name_list.txt","w") as file_object:
file_object.write(name)
结果展示: