title: Python overwriting variables in nested functions
body: <p>Suppose I have the following python code:</p>
  
  <pre><code>def outer():
      string = ""
      def inner():
          string = "String was changed by a nested function!"
      inner()
      return string
  </code></pre>
  
  <p>I want a call to outer() to return "String was changed by a nested function!", but I get "". I conclude that Python thinks that the line <code>string = "string was changed by a nested function!"</code> is a declaration of a new variable local to inner(). My question is: how do I tell Python that it should use the outer() string? I can't use the <code>global</code> keyword, because the string isn't global, it just lives in an outer scope. Ideas?</p>