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

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

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