#有两个文件file1.txt和file2.txt,各存放一行字符, 编写一个程序将文件内容合并到一起并写入file3.txt文件中。
fp1=open("D:\\file1.txt","r+")
r1=fp1.read()
list1=list(r1)#将字符串转换为列表
fp2=open("D:\\file2.txt","r+")
r2=fp2.read()
list2=list(r2)
fp3=open("D:\\file3.txt","r+")
r3=fp3.read()
fp3.write(r1+r2)#写入fp3
print(fp)
fp3.close()
文件在D盘创建
结果: