\r 回到行首
\n 换行
\r\n 回到行首并换行
在对文件进行读写操作时,发现\r和\n的效果一样
演示\r
f=open("try_rw2.txt","w+")
f.write("hello\rworld")
print(f.tell()) #输出当前文件读写指针的位置
f.seek(0,0) #把文件读写指针移到文件的开始
content=f.read()
print(content)
print(f.tell())
f.close()
结果:
演示\n
f=open("try_rw2.txt","w+")
f.write("hello\nworld")
print(f.tell()) #输出当前文件读写指针的位置
f.seek(0,0) #把文件读写指针移到文件的开始
content=f.read()
print(content)
print(f.tell())
f.close()
结果:
演示\r\n