title: Instance variables in methods outside the constructor (Python) -- why and how?
body: <p>My questions concern instance variables that are initialized <em>in methods outside the class constructor</em>. This is for Python. </p>
  
  <p>I'll first state what I understand: </p>
  
  <ol>
  <li>Classes may define a constructor, and it may also define other methods.</li>
  <li>Instance variables are generally defined/initialized within the constructor.</li>
  <li>But instance variables can also be defined/initialized <em>outside</em> the constructor, e.g. in the other methods of the same class. </li>
  <li><p>An example of (2) and (3) -- see <em>self.meow</em> and <em>self.roar</em> in the <strong>Cat</strong> class below:</p>
  
  <pre><code>class Cat():
  
      def __init__(self):
          self.meow = "Meow!"
      def meow_bigger(self):
          self.roar = "Roar!"
  </code></pre></li>
  </ol>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>Why is it best practice to initialize the instance variable within the constructor? </p></li>
  <li><p>What general/specific mess could arise if instance variables are regularly initialized in methods other than the constructor? (E.g. Having read Mark Lutz's  Tkinter guide in his Programming Python, which I thought was excellent, I noticed that the instance variable used to hold the PhotoImage objects/references were initialized in the further methods, not in the constructor. It seemed to work without issue there, but could that practice cause issues in the long run?)</p></li>
  <li><p>In what scenarios would it be <em>better</em> to initialize instance variables in the other methods, rather than in the constructor?</p></li>
  </ol>
  
  <hr>
  
  <ol start="4">
  <li><p>To my knowledge, instance variables exist not when the class object is created, but <em>after</em> the class object is instantiated. Proceeding upon my code above, I demonstrate this: </p>
  
  <pre><code>&gt;&gt; c = Cat() 
  &gt;&gt; c.meow
  'Meow!'
  &gt;&gt; c.roar
  Traceback (most recent call last):
   File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'Cat' object has no attribute 'roar'
  &gt;&gt;&gt; c.meow_bigger()
  &gt;&gt;&gt; c.roar
  'Roar!'
  </code></pre>
  
  <p>As it were:</p>
  
  <ul>
  <li>I cannot access the instance variable (<em>c.roar</em>) at first. </li>
  <li>However, after I have called the instance method <em>c.meow_bigger()</em> once, I am suddenly able to access the instance variable <em>c.roar</em>. </li>
  <li>Why is the above behaviour so?</li>
  </ul></li>
  </ol>
  
  <p>Thank you for helping out with my understanding.</p>