python問題:IndentationError:expected an indented block錯誤解決《轉》

來源:互聯網
上載者:User

標籤:cat   冒號   details   帶來   nts   content   one   程式員   出錯   

python問題:IndentationError:expected an indented block錯誤解決標籤: python語言2012-07-07 17:59 125145人閱讀 評論(9) 收藏 舉報 分類:python學習筆記(2) 

原文地址:http://hi.baidu.com/delinx/item/1789d38eafd358d05e0ec1df

   

Python語言是一款對縮排非常敏感的語言,給很多初學者帶來了困惑,即便是很有經驗的Python程式員,也可能陷入陷阱當中。最常見的情況是tab和空格的混用會導致錯誤,或者縮排不對,而這是用肉眼無法分別的。

在編譯時間會出現這樣的錯IndentationError:expected an indented block說明此處需要縮排,你只要在出現錯誤的那一行,按空格或Tab(但不能混用)鍵縮排就行。

往往有的人會疑問:我根本就沒縮排怎麼還是錯,不對,該縮排的地方就要縮排,不縮排反而會出錯,,比如:

if xxxxxx:

(空格)xxxxx

或者

def xxxxxx:

(空格)xxxxx

還有

for xxxxxx:

(空格)xxxxx

一句話 有冒號的下一行往往要縮排,該縮排就縮排

python問題:IndentationError:expected an indented block錯誤解決《轉》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.