立即学习:https://edu.csdn.net/course/play/25784/313745?utm_source=blogtoedu
file = open('demo.txt','r') data = file.read() print(data) file.close() filex = open('demo.txt','r') data2 = filex.readlines() print("this is data2:") print(data2) file.close() file2 = open('demo2.txt','a',encoding='utf-8') file2.write('我爱python3!') file2.close() file3 = open('demo2.txt','r',encoding='utf-8') data3 = file3.read() print('this is data3:') print(data3) with open('demo.txt','r') as f: data4 = f.readlines() # f.close() print('This is data4:') print(data4) f.close() with open('demo.txt','r') as f2: data5 = f2.read() f2.close() print('this is data5:') print(data5)