python自学菜鸟 expected an indented block什么意思

如题所述

该缩进的地方没有缩进,就会报错expected an indented block

因为Python语言是一款对缩进非常敏感的语言

比如下面的代码

a = 1
b=0
if a>b:
print "a>b"

会报错

 File "D:/num.py", line 4

    print "a>b"

        ^

IndentationError: expected an indented block

修改如下

a = 1
b=2
if a>b:
    print "a>b"

从属代码块, 需要缩进


从属代码块, 需要缩进的关键字主要有

if、while、for、try-except,def 等

温馨提示:答案为网友推荐,仅供参考
相似回答