title: Python - Changing global variable in a function
body: <p>I have the following code in python:</p>
  
  <pre><code>board = 0
  
  def Board1():
      global board
      board = 1
  
  def Board2():
      global board
      board = 2
  
  def Board3(board):
      board = 3
      print board
  
  def ReadBoard():
      print board
  </code></pre>
  
  <p>I think the functions Board1 and Board2 should change the value of the global variable board. But here is what happens: When I call board it returns 0. If I call Board1, the global board value does not change, but if I call ReadBoard, it gives the value Board1 has assigned.
  For example (in python console):</p>
  
  <pre><code>&gt;&gt;&gt; board  
  0  
  &gt;&gt;&gt; Board1()  
  &gt;&gt;&gt; board  
  0  
  &gt;&gt;&gt; ReadBoard()  
  1  
  &gt;&gt;&gt; Board3(board)
  3  
  &gt;&gt;&gt; board  
  0  
  &gt;&gt;&gt; board = 4
  &gt;&gt;&gt; ReadBoard()
  1  
  </code></pre>
  
  <p>I could not understand why I cannot change the global variable globally and why am I reading the changed variable in the ReadBoard function.</p>