What is wrong with what I am doing? In the approach, the control always goes back to the else
part even after coming to the if
clause:
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)
You need to add return
to the end of the function to explicily return the value of the recursive function. And better use 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.