- 最終更新
- 2026/08/17
3秒でわかる
行頭の字下げのこと。Pythonでは見た目を整える習慣ではなく文法そのもので、量がずれるとエラーになるか結果が変わります。
30秒図解
もう少し詳しく
どういうものか
インデントはif や for や def の
字下げの
なぜ必要か
他の
具体例
字下げの位置が1段違うだけで、
total = 0
for price in [100, 200, 300]:
total += price
print(total) # ループの中なので3回出力される
total = 0
for price in [100, 200, 300]:
total += price
print(total) # ループの外なので最後に1回だけ上は
つまずきやすいところ
最もTabError に
次にIndentationError: unexpected indent はif のIndentationError: expected an indented block にpass を1行置いて
if stock == 0:
pass # 後で在庫切れの処理を書く似た用語との違い
インデントは

