In a Python class, what is the difference between creating a variable with the self syntax, and creating one without ?
<p>What is the difference between creating a variable using the self.variable syntax and creating one without? </p>

<p>I was testing it out and I can still access both from an instance: </p>

<pre><code>class TestClass(object):
    j = 10
    def __init__(self):
        self.i = 20

if __name__ == '__main__':
    testInstance = TestClass()
    print testInstance.i
    print testInstance.j
</code></pre>

<p>However, if I swap the location of the <code>self</code>, it results in an error. </p>

<pre><code>class TestClass(object):
    self.j = 10
    def __init__(self):
        i = 20

if __name__ == '__main__':
    testInstance = TestClass()
    print testInstance.i
    print testInstance.j  

&gt;&gt;NameError: name 'self' is not defined
</code></pre>

<p>So I gather that self has a special role in initialization.. but, I just don't quite get what it is.</p>
