# 写入文本文件 with open('example.txt', 'w') as f: f.write('Hello, Python!') # 读取文本文件 with open('example.txt', 'r') as f: print(f.read())