title: What is the difference between declaring data attributes inside or outside __init__
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/207000/python-difference-between-class-and-instance-attributes">Python: Difference between class and instance attributes</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to get my head around OOP in Python and I'm a bit confused when it comes to declare variables within a class. Should I declare them inside of the <code>__init__</code> procedure or outside it? What's the difference?</p>
  
  <p>The following code works just fine:</p>
  
  <pre><code># Declaring variables within __init__
  class MyClass:
      def __init__(self):
          country = ""
          city = ""
      def information(self):
          print "Hi! I'm from %s, (%s)"%(self.city,self.country)
  
  me = MyClass()
  me.country = "Spain"
  me.city = "Barcelona"
  me.information()
  </code></pre>
  
  <p>But declaring the variables outside of the <code>__init__</code> procedure also works:</p>
  
  <pre><code># Declaring variables outside of __init__
  class MyClass:
      country = ""
      city = ""
      def information(self):
          print "Hi! I'm from %s, (%s)"%(self.city,self.country)
  
  me = MyClass()
  me.country = "Spain"
  me.city = "Barcelona"
  me.information()
  </code></pre>