logo

🧪 循环语句

⏱️ 20-25 min📊 Beginner
main.py
Costs 1 credit
加载编辑器中...
输出 Output执行成功
# 运行代码后,输出将显示在这里
# 按 Ctrl+Enter 快速运行
Terminal (Simulated)Install commands are simulated only, no real network requests
$

Step 1: for 循环基础

for 循环是“逐个处理数据集合”的首选工具,适合列表、字符串、字典等可迭代对象。

底层逻辑:
for x in sequence 会让变量 x 依次绑定到序列中的每个元素。
每轮执行同一段代码,实现“相同处理应用到不同数据”。
像点名:名单里每个人都会被叫到一次,每叫到一个就执行同样动作(打印)。

你的任务

  1. 创建列表 fruits = ["apple", "banana", "cherry"]
  2. 使用 for 循环输出每个水果

Self-Check List

  • 使用 for 循环遍历列表

Transfer Template

for fruit in fruits:
    print(fruit)
After completing this step, you should be able to independently explain and reproduce this concept, then apply it to similar problems.

验证清单 (0/0)