title: Dynamically defining instance fields in Python classes
body: <p>I am new to Python having come from mainly Java programming. </p>
  
  <p>I am currently pondering over how classes in Python are instantiated.</p>
  
  <p>I understand that <code>__init__()</code>: is like the constructor in Java. However, sometimes python classes do not have an <code>__init__()</code> method which in this case I assume there is a default constructor just like in Java? </p>
  
  <p>Another thing that makes the transition from Java to python slightly difficult is that in Java you have to define all the instance fields of the class with the type and sometimes an initial value. In python all of this just seems to disappear and developers can just define new fields on the fly. </p>
  
  <p>For example I have come across a program like so:</p>
  
  <pre><code>class A(Command.UICommand):
      FIELDS = [
          Field( 'runTimeStepSummary', BOOL_TYPE)
          ]
  
      def __init__(self, runTimeStepSummary=False):
          self.runTimeStepSummary = runTimeStepSummary
  
      """Other methods"""
  
      def execute(self, cont, result):
          self.timeStepSummaries = {}
          """ other code"""
  </code></pre>
  
  <p>The thing that confuses (and slightly irritates me) is that this A class does not have a field called timeStepSummaries yet how can a developer in the middle of a method just define a new field? or is my understanding incorrect?</p>
  
  <p>So to be clear, my question is in Python can we dynamically define new fields to a class during runtime like in this example or is this timeStepSummaries variable an instance of a java like private variable?</p>
  
  <p>EDIT: I am using python 2.7</p>