文件读写(一行一行)

`# 写入文件
with open("test.txt", "w") as f:
f.write("第一行\n第二行")

读取并打印

with open("test.txt", "r") as f:
for line in f:
print(line.strip())`
知识点: 打开文件、读取行、写入新文件

posted @ 2026-05-19 18:22  白底纸板  阅读(8)  评论(0)    收藏  举报