title: global variables from separate functions?
body: <p>I've been trying to understand the behaviour of <code>global</code> variables in Python. From <a href="https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them">here</a>, I gather that I can <strong>read</strong> any variable defined in an <strong>outer scope</strong>. If I want to <strong>modify</strong> it in an <strong>inner scope</strong>, I have to "declare" as <code>global</code> in that <strong><em>inner</em></strong> scope, so that Python looks for it according to its <a href="https://stackoverflow.com/questions/291978/short-description-of-python-scoping-rules">scoping rules</a> and knows I'm not creating a new local variable.</p>
  
  <p>But why does the following correctly print the values of variables <code>a</code> and <code>b</code>?</p>
  
  <pre><code>import sys
  
  def func1():
      print a # will print 1
      print b # will print 2
      return
  
  def main():
      global a 
      a = 1
      global b
      b = 2
      func1()
      return 0
  
  if __name__ == '__main__':
      status = main()
      sys.exit(status)
  </code></pre>