title: Python: How can a closure continue its existence after the outer function is reassigned?
body: <p>I learning about closures in Python, and I get the concept well enough. While messing around in IDLE I thought about what would happen if I reassigned the enclosing function and then tried to call the enclosed function:</p>
  
  <pre><code>&gt;&gt;&gt; def outer_function(hello):
          message = hello
          def inner_function():
              print(message)
          return inner_function
  
  &gt;&gt;&gt; function = outer_function("hello")
  
  &gt;&gt;&gt; function()
  hello
  
  &gt;&gt;&gt; def outer_function():
      print("hi")
  
  &gt;&gt;&gt; function()
  hello
  </code></pre>
  
  <p>I think that this is very interesting, but I realize that I do not have a good enough understanding about what happens to the closure in memory etc. Can someone explain how I can call <code>inner_function</code> after reassignment of <code>outer_function</code>? </p>