I'm currently learning Python and recursive function. I'm just stuck with it that do not actually know what happened after the recursive step is executed. I have an example such
# sum of list
def my_sum(L):
# this step is just print out current list
# at each level
print(L)
if not L:
return 0
else:
return L[0] + my_sum(L[1:])
and the result for the above function is
[1,2,3,4,5]
[2,3,4,5]
[3,4,5]
[4,5]
[5]
[]
15
I've read a few articles about recursion and understood a bit. However, in this case, I don't see that size of L is decreased at all, so how can the list is growing smaller like that?
Could someone figure this out for me?
Thank you!