天天看點

Python報錯 IndentationError: unexpected indent / IndentationError: expected an indented block

以上都是 縮進錯誤: 期望一個縮進的塊

Python 有着嚴格的代碼縮進,縮進的代碼塊相對于上一級是從屬關系。

Python 是以 縮進 為邏輯代碼分割符号 的語言 類似C語言中的大括号 {}

解決方法:嚴格 縮進

例子:

if xxxxxx:

(空格)xxxxx

或者

def xxxxxx:

(空格)xxxxx

還有

for xxxxxx:

(空格)xxxxx

Python報錯 IndentationError: unexpected indent / IndentationError: expected an indented block
Python報錯 IndentationError: unexpected indent / IndentationError: expected an indented block