title: Can someone please explain this bit of Python code?
body: <p>I started working in Python just recently and haven't fully learned all the nuts and bolts of it, but recently I came across <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/67666" rel="noreferrer">this post</a> that explains why python has closures, in there, there is a sample code that goes like this:</p>
  
  <pre><code>y = 0
  
  def foo():
      x = [0]
      def bar():
          print x[0], y
      def change(z):
          global y
          x[0] = y = z
  
      change(1)
      bar()
      change(2)
      bar()
      change(3)
      bar()
      change(4)
      bar()
  
  foo()
  
  1 1
  2 2
  3 3
  </code></pre>
  
  <p>and basically I don't understand how it actually works, and what construct like x[0] does in this case, or actually I understand what it's doing, I just don't get how is it this :)</p>