Python - Function Function Recursion

Introduction

To sum a list of numbers, we can use recursive function.

Demo

def mysum(L): 
   if not L: 
       return 0 #   ww w  .  j a  v a2  s  .  c  o  m
   else: 
       return L[0] + mysum(L[1:])           # Call myself recursively 
d=mysum([1, 2, 3, 4, 5]) 
print( d )

Result

Here, this function calls itself recursively to compute the sum of the rest of the list.