[Tutor] classes : post-declaration attributes
neubyr at gmail.com
Sat Feb 9 08:01:37 CET 2013
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,
self.val1 = arg
a = A(1)
Now another data attribute val2 can be added as:
a.val2 = 2
A.val2 = 22
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 .
So does it mean post-declaration attributes are invalid? Why are they
allowed to be created then (any special use cases/examples)?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor