1.with open:
with open(文件索引,"w","编码(可写可不写)") as 变量:
变量.write("内容")
2.print写入:
print("内容",file=open(文件索引,"w","编码(可写可不写)"))
3.直接open:
变量=open(文件索引,"w","编码(可写可不写)")
变量.write("内容")
变量.close()
如果要换行就需要\n,就像这样:
1.wiith open:
with open(文件索引,"w") as 变量:
变量.write("内容\n")
变量.write("内容")
2.print写入:
print("内容\n"+"内容",file=open(文件索引,"w","编码(可写可不写)"))
3.直接open:
变量=open(文件索引,"w","编码(可写可不写)")
变量.write("内容\n")
变量.write("内容")
变量.close()
利用这个,可以做一个简易记事本: