Some say that return
returns the value to the function. While learning DSA some referred, (in recursion) when "return" is used or when the base case hits, values are printed down the stack.
Example:
def print_sum(i, n, sum):
if i==n:
sum += n
print(sum)
return sum
else:
sum += i
print_sum(i+1,n,sum)
# print(i)
print(print_sum(1,5,0))
If return
is returning the value to the function, why does print(print_sum(1,5,0))
show None
as the output. This should provide "sum" i.e 15
as output as I have returned sum.