How does the global variable behave inside function(Python) : <p>Case 1</p>

<pre><code>A = '213'
def wow():
    print(A)
wow()
Output: '213'
</code></pre>

<p>Case 2</p>

<pre><code>A = '213'
def wow():
    print(A)
    A = 12
wow()
Output: UnboundLocalError: local variable 'A' referenced before assignment
</code></pre>

<p>I'd thought that the output in the case 2 would be identical to the case 1, since A is a global variable and I called "print(A)" <em>before</em> reassigning value to A within the function. So my question is, why in the case 1 calling A is  perfectly fine, but case 2 throws error?</p>
