logo

🧪 文件读写

⏱️ 20-25 min📊 Intermediate
main.py
Costs 1 credit
加载编辑器中...
输出 Output执行成功

[错误提示]
检测到中文全角符号(如 ( ) , : ;),Python 语法可能无法解析。
请改成英文半角符号:( ) , : ;
Terminal (Simulated)Install commands are simulated only, no real network requests
$

Step 1: 模拟文件操作

    <p>先用字符串模拟文件,是为了把注意力放在“读取流程”而不是环境权限。</p>
    <div class="concept-block">
      <strong>底层逻辑:</strong><br/>
      文件读取本质是把字节流转成文本行。<code>splitlines()</code> 模拟的就是“按行切分”这一步。
    </div>
    <p><strong>你的任务</strong>:</p>
    <ol>
      <li>创建一个包含多行文本的字符串(模拟文件内容)</li>
      <li>使用 <code>splitlines()</code> 分割成行</li>
      <li>打印每一行</li>
    </ol>
    <p>示例内容:</p>
    <pre>Hello World

Python is fun File I/O is easy

Self-Check List

  • 模拟文件内容
  • 分割行
  • 遍历打印

Transfer Template

file_content = """Hello World
Python is fun
File I/O is easy"""
lines = file_content.splitlines()
After completing this step, you should be able to independently explain and reproduce this concept, then apply it to similar problems.

验证清单 (0/0)