Error: IndentationError: expected an indented block
Where?
Python代码执行时候报这个错误
Why?
Python代码具有严格缩进规范,默认规范为一层缩进为4个空格,但可以缩进至少一个空格,推荐按规范来,这个出错函数下下缩进错误
Way?
检查缩进,修改正确
错误代码:
class Num(object):
def __init__(self, num):
self.num = num
def __abs__(self):
# 缩进不正确
return abs(self.num)
num = Num(-10)
print(abs(num))
正确代码:
class Num(object):
def __init__(self, num):
self.num = num
def __abs__(self):
# 缩进正确
return abs(self.num)
num = Num(-10)
print(abs(num))