一、读写txt文件

1、打开txt文件

Note=open('x.txt',mode='w',encoding='utf-8')

函数=open(x.扩展名,mode=模式)

模式种类:

w       只能操作写入(如果而文件中有数据,再次写入内容,会把原来的覆盖掉)
r        只能读取
a       向文件追加
w+     可读可写
r+      可读可写
a+     可读可追加
wb+   写入数据

2、向文件中写入数据

第一种写入方式:

write 写入

Note.write('hello word 你好 \n') #\n 换行符

3、关闭文件

Note.close()

二、读取txt文件

content=Note.read()