Why does python think this is a local variable?
<p>I have a global variable I called Y_VAL which is initialized to a value of 2. </p>

<p>I then have a function, called f() (for brevity), which uses Y_VAL.</p>

<pre><code>def f():
    y = Y_VAL
    Y_VAL += 2
</code></pre>

<p>However, when trying to run my code, python gives the error message:</p>

<pre><code>UnboundLocalError: local variable 'Y_VAL' referenced before assignment
</code></pre>

<p>If I remove the last line <code>Y_VAL += 2</code> it works fine. </p>

<p>Why does python think that Y_VAL is a local variable?</p>
