title: Why can't I access an class variable defined in __init__ from outside of the class?
body: <p>I was wondering about classes and how I can access their values from the outside with either printing it or using the _str__ function. I came across this question:
  <a href="https://stackoverflow.com/questions/16680221/python-function-not-accessing-class-variable">Python function not accessing class variable</a></p>
  
  <p>Then I did this test in Shell, but it didn't work as expected. I wonder why the other answer worked, but not this one.</p>
  
  <p>(edit)
  My question was answered by how to instantiate a class, not instance variables.</p>
  
  <pre><code>&gt;&gt;&gt; class test:
      def __init__(self):
          self.testy=0
      def __str__(self):
          return self.testy
  
  
  &gt;&gt;&gt; a=test
  &gt;&gt;&gt; b=test
  &gt;&gt;&gt; print(a)
  &lt;class '__main__.test'&gt;
  &gt;&gt;&gt; a
  &lt;class '__main__.test'&gt;
  &gt;&gt;&gt; a.testy
  Traceback (most recent call last):
    File "&lt;pyshell#10&gt;", line 1, in &lt;module&gt;
      a.testy
  AttributeError: type object 'test' has no attribute 'testy'
  &gt;&gt;&gt; 
  </code></pre>