title: How do nested functions work in Python?
body: <pre><code>def maker(n):
      def action(x):
          return x ** n
      return action
  
  f = maker(2)
  print(f)
  print(f(3))
  print(f(4))
  
  g = maker(3)
  print(g(3))
  
  print(f(3)) # still remembers 2
  </code></pre>
  
  <p>Why does the nested function remember the first value <code>2</code> even though <code>maker()</code> has returned and exited by the time <code>action()</code> is called?</p>