[英]python: recursive method understanding
我在做什么有什么问题? 在该方法中,即使在进入if
子句之后,控件也始终返回到else
部分:
def recurse(param1, param2):
is_bool = some_func_that_returns_boolean(param1, param2)
if is_bool is False:
return 1 # exit the func
else:
recurse(param1, param2)
您需要在函数末尾添加return
以明确返回递归函数的值。 if not
,最好使用:
def recurse(param1, param2):
is_bool = some_func_that_returns_boolean(param1, param2)
if not is_bool:
return 1 # exit the func
else:
return recurse(param1, param2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.