title: Storing Variables in Python Class
body: <p>I am trying to establish the difference between these two methods of creating variables in a class and which method is correct?</p>
  <pre><code>class example():
      var = 12
  
  class example2():
      def __init__(self):
          self.var = 34
  
  ob1 = example()
  ob2 = example2()
  
  print (ob1.var)
  print (ob2.var)
  </code></pre>
  <p>This returns the contents of the variables as expected:</p>
  <pre><code>12
  34
  &gt;&gt;&gt; 
  </code></pre>
  <p>I have searched stackoverflow to see if there is anything on this and couldn't find anything that compared the two, I find its always easier to search when you know the answer.</p>
  <p>Thank you</p>