公開:2025-05-22、更新:2025-05-22
7-6「リストやfor文の入れ子」 6ページ
マンガ

6
コンテンツ紹介
テキスト原稿
# 6p
__1__
猫野:
処理を全て
順番に書いて
いってみよう
__2__
```py
data = [
[10, 20, 30],
[42, 50, 60]
]
for data2 in data:
for item in data2:
print(item)
```
---
__3__
外側のfor文 dataから [10, 20, 30] を取り出してdata2に代入
内側のfor文 data2から 10 を取り出してitemに代入
「10」を出力
内側のfor文 data2から 20 を取り出してitemに代入
「20」を出力
内側のfor文 data2から 30 を取り出してitemに代入
「30」を出力
外側のfor文 dataから [40, 50, 60] を取り出してdata2に代入
内側のfor文 data2から 40 を取り出してitemに代入
「40」を出力
内側のfor文 data2から 50 を取り出してitemに代入
「50」を出力
内側のfor文 data2から 60 を取り出してitemに代入
「60」を出力