首页 > 其他 > 详细

IndentationError: expected an indented block

时间:2020-02-27 19:29:54      阅读:84      评论:0      收藏:0      [点我收藏+]

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即可快速缩进

 

 

 

IndentationError: expected an indented block

原文:https://www.cnblogs.com/-lemon/p/12373661.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!