<div><br></div><span style="font-family:sans-serif;font-size:16px;line-height:20px;text-align:justify;background-color:rgb(255,255,255)"><div>I am learning Python 2.7 classes and objects. It seems like attributes (data attributes and methods) can be added to a class/object  even after it's first declaration. For example,</div>
<div><br></div><div><code></div><div>class A(object):</div><div>  def __init__(self,arg):</div><div>    self.val1 = arg</div><div><br></div><div>a = A(1)</div><div>print a.val1</div><div></code></div><div><br>
</div><div>Now another data attribute val2 can be added as:</div><div><code></div><div>a.val2 =  2</div><div>A.val2 = 22</div><div></code></div><div><br></div><div>I understand that all attributes are stored in a dictionary, but I am not following when adding an attribute after initial declaration approach should be used. The official documentation also suggests that valid attributes are all the names present when the class object was created [1]. So does it mean post-declaration attributes are invalid? Why are they allowed to be created then (any special use cases/examples)?</div>
<div><br></div><div>1. <a href="http://docs.python.org/2/tutorial/classes.html">http://docs.python.org/2/tutorial/classes.html</a> </div><div><br></div><div>--</div><div>thanks,</div><div>N</div><div><br></div></span>