How does Python print a variable that is out of scope
<p>I have the following function in Pyton that seems to be working:</p>

<pre><code>def test(self):
    x = -1
    # why don't I need to initialize y = 0 here?
    if (x &lt; 0):
        y = 23

    return y
</code></pre>

<p>But for this to work why don't I need to initialize variable y? I thought Python had block scope so how is this possible? </p>

<p>As in <a href="http://stackoverflow.com/questions/2829528/whats-the-scope-of-a-python-variable-declared-in-an-if-statement">What&#39;s the scope of a Python variable declared in an if statement?</a>: "Python variables are scoped to the innermost function or module; control blocks like if and while blocks don't count."</p>

<p>Also useful: <a href="http://stackoverflow.com/questions/291978/short-description-of-python-scoping-rules">Short Description of Python Scoping Rules</a> </p>

python block