【发布时间】:2020-11-23 19:42:24
【问题描述】:
def primes_number(number = 5):
for x in range(1, number):
for y in range(2, x):
if((number % x) == 0):
else:
print(y)
print(primes_number())
line 9
else:
^
IndentationError: expected an indented block
为什么程序会在这里看到问题? 当我删除 else 时:我只有“none”作为输出,这很奇怪。
【问题讨论】:
-
如果
if里面什么都没有,你必须在ifbody里面使用pass -
Python 不允许空块。在
if中添加pass语句。重复:stackoverflow.com/questions/1528903/… -
主要的
print确实打印了该方法返回的内容,并且由于该方法没有return它显示为None