r_stack stack(def to_str(nbase)convert_string " abcdefwhile if baser_stack push(convert_string[ ]elser_stack push(convert_string[ base] /base res "while not r_stack is_empty()res res str(r_stack pop()return res print(to_str( )each time we make call to tostrwe push character on the stack returning to the previous example we can see that after the fourth call to tostr the stack would look like figure notice that now we can simply pop the characters off the stack and concatenate them into the final result" figure strings placed on the stack during conversion the previous example gives us some insight into how python implements recursive function call when function is called in pythona stack frame is allocated to handle the local variables of the function when the function returnsthe return value is left on top of the stack for the calling function to access figure illustrates the call stack after the return statement on line notice that the call to tostr( // leaves return value of "on the stack this return value is then used in place of the function call (tostr( )in the expression " convertstring[ % ]which will leave the string " on the top of the stack in this waythe python call stack takes the place of the stack we used explicitly earlier in our list summing exampleyou can think of the return value on the stack taking the place of an accumulator variable the stack frames also provide scope for the variables used by the function even though we are calling the same function over and overeach call creates new scope for the variables that are local to the function recursion