title: accessing global frames in a user defined function
body: <pre><code>a = 4
  def foo(x):
      a = 10
  foo(2)
  print(a)
  #prints 4
  </code></pre>
  
  <p>The code above doesn't change <code>a</code></p>
  
  <pre><code>a = 4
  def foo(x):
     return a + x
  result = foo(10)
  print(result)
  #prints out 14
  </code></pre>
  
  <p>I don't quite understand how these two act differently. The second one, the global variable obviously affects the local variable in <code>foo</code>. But if I change <code>a</code> in the first one inside the <code>foo</code>, nothing happens to <code>a</code> in the global frame. What is happening?</p>