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,

<code>
class A(object):
  def __init__(self,arg):
    self.val1 = arg

a = A(1)
print a.val1
</code>

Now another data attribute val2 can be added as:
<code>
a.val2 =  2
A.val2 = 22
</code>

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)?

1. http://docs.python.org/2/tutorial/classes.html

--
thanks,
N
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to