title: Passing a slice to recursive function in Python
body: <p>I think I understand the basic principles of recursive functions and slicing (individually), but I am having trouble putting them together. I don't understand what happens when you pass a slice or a list to the following function.</p>
  
  <pre><code>def listSum(ls):
      # Base condition
      if not ls:
          return 0
  
      # First element + result of calling `listsum` with rest of the elements
      return ls[0] + listSum(ls[1:])
  
  listSum([1, 3, 4, 5, 6])
  19
  </code></pre>
  
  <p>This is the thread that contains this code:
  <a href="https://stackoverflow.com/questions/11693819/understanding-recursion-in-python">Understanding recursion in Python</a></p>
  
  <p>I think I would really benefit from a walk-through of what happens when the function is called.</p>
  
  <p>The thread has a lot of examples of different recursive functions, with the expected output. I understand the subsequent examples even less than the one I copied above.</p>