求教个python递归的问题,谢谢
下面的代码elif和else语句里为什么一定要加return 输出才正确,为什么不能直接递归调用函数def trim(s):
if s[:1] != " " and s[-1:] != " ":
return s
elif s[:1] == " ":
return trim(s[1:])
else:
return trim(s[:-1])
if __name__ == "__main__":
s = trim(" hello")
print s