Python中expected an indented block

原文地址为: Python中expected an indented block

Python严格地要求代码缩进,缩进的代码块相对于上一级是从属关系。用if语句举个例子:
if a==2: print 'hello world'if语句的条件为真时会执行print语句,print语句是if语句的从属代码块,代表从属关系,print语句之前有4个空格。如果if语句没有任何从属的代码块就会报错expected an indented block。与if语句类似的,必须包含从属代码块的还有while、for、try-except等。

转载请注明本文地址: Python中expected an indented block

猜你喜欢

转载自blog.csdn.net/dearbaba_1666/article/details/80774093