← 返回题库
初级

文件逐行读取

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
with open('test.txt', 'w') as f:
    f.write('line1
line2
line3
')
with open('test.txt', 'r') as f:
    for line in f:
        print(line.strip())
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码