I have a function:
def sum(list):
if list == []:
return 0
return 1 + sum(list[1:])
And I couldn't find anywhere a normal explanation of how this part of the function works:
return 1 + sum(list[1:])
Why is 1 being added to the cut [1:] list, why is the cut [1:] list, what happens when 1 is added, and also why when I try to add 1 to the cut [1:] array outside of recursion, I get an error
Thanks in advance:)