IndentationError: expected an indented block

Python使用for循环遍历列表

代码: 

fruits=['apple','pear','grape','mango','lemon']
for fruit in fruits :
print(fruit)

错误:

IndentationError: expected an indented block #期望一个缩进的块

原因:

  在c语言和Java中都是用花括号{ }来区分一个块的,而在python中是用缩进来识别语法逻辑块,类似的有if、while等

纠正:

 

fruits=['apple','pear','grape','mango','lemon']
for fruit in fruits :
    print(fruit)

 

在sublime中使用Tab即可快速缩进

 

 

 

posted @ 2020-02-27 18:47  cute_lemon  阅读(348)  评论(0)    收藏  举报