【发布时间】:2021-10-18 15:50:53
【问题描述】:
我最近在学习递归,写了一个简单的递归函数来验证我的理解:
def hello(n):
if n == 1:
return 'hello'
else:
print('hello')
hello(n-1)
def returnhello():
return 'hello'
print(returnhello())
print()
print(hello(5))
这里显示了它的输出:
hello
hello
hello
hello
hello
None
为什么递归中的最后一个调用打印 None 而不是 hello?我期待它打印 5 hello
【问题讨论】: