at each levelthis function calls itself recursively to compute the sum of the rest of the listwhich is later added to the item at the front the recursive loop ends and zero is returned when the list becomes empty when using recursion like thiseach open level of call to the function has its own copy of the function' local scope on the runtime call stack--herethat means is different in each level if this is difficult to understand (and it often is for new programmers)try adding print of to the function and run it againto trace the current list at each call leveldef mysum( )print(lif not lreturn elsereturn [ mysum( [ :]trace recursive levels shorter at each level mysum([ ][ [ [ [ [ [ as you can seethe list to be summed grows smaller at each recursive leveluntil it becomes empty--the termination of the recursive loop the sum is computed as the recursive calls unwind on returns coding alternatives interestinglywe can use python' if/else ternary expression (described in to save some code real estate here we can also generalize for any summable type (which is easier if we assume at least one item in the inputas we did in ' minimum value exampleand use python ' extended sequence assignment to make the first/rest unpacking simpler (as covered in )def mysum( )return if not else [ mysum( [ :]use ternary expression def mysum( )return [ if len( = else [ mysum( [ :]any typeassume one def mysum( )first*rest return first if not rest else first mysum(restuse ext seq assign the latter two of these fail for empty lists but allow for sequences of any object type that supports +not just numbers advanced function topics