首页 > 编程语言 > 详细

python问题:IndentationError:expected an indented block错误

时间:2019-01-09 19:17:59      阅读:176      评论:0      收藏:0      [点我收藏+]

Python语言是一款对缩进非常敏感的语言,最常见的情况是tab和空格的混用会导致错误,或者缩进不对。

>>> a=100
>>> if a>=0:
... print a
File "<stdin>", line 2
print a
^
IndentationError: expected an indented block
1
2
3
4
5
6
7
在编译时会出现这样的错IndentationError:expected an indented block说明此处需要缩进,你只要在出现错误的那一行,按空格或Tab(但不能混用)键缩进就行。

修改后如下:

>>> a=100
>>> if a>=0:
... print a
... else:
... print -a
...
100
缩进要使用4个空格(这不是必须的,但你最好这么做),缩进表示一个代码块的开始,非缩进表示一个代码的结束。没有明确的大括号、中括号、或者关键字。这意味着空白很重要,而且必须要是一致的。第一个没有缩进的行标记了代码块,意思是指函数,if 语句、 for 循环、 while 循环等等的结束。
原文:https://blog.csdn.net/qq_15437667/article/details/52558999

python问题:IndentationError:expected an indented block错误

原文:https://www.cnblogs.com/gkh-whu/p/10246305.html

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