0

Is it necessary for python recursive function to return a value??

We define a base case which returns a known value. But is it possible for any recursive function in python to not return any value and still do the recursion??

6th Jun 2021, 5:41 PM
Optimus Prime
Optimus Prime - avatar
2 Answers
+ 5
Yes You could have your base case print(something), then on the next line put return The return will stop the recursion without returning a value
6th Jun 2021, 7:28 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Yes. You can have the function print a value or do some other action instead of return a value. It is only necessary that the input value signals the end of recursion. Edit: Oops, Somehow I overlapped with Rik Wittkopp's answer. It was not there at first when I viewed the question.
6th Jun 2021, 9:59 PM
Brian
Brian - avatar