python class instantiation
fredrik at pythonware.com
Mon Oct 23 23:02:32 CEST 2006
Éric Daigneault lists wrote:
> When creating a class with data members but no __init__ method. Python
> deals differently with data members that are muatable and immutables.
no, it doesn't. it's your code that deals with them in different ways,
> class A(object):
> stringData = "Whatever"
> listData = 
> instance = A()
> Will have data members instantiated as expected (instance.stringData ==
> "Whatever" and instance.listData == )
here, you call a method on the class object. this method modifies the
> instance.stringData = "Changed"
here, you use assignment to *add* a new attribute to the instance.
the class attribute is still there, but it's shadowed by an instance
attribute with the same name.
More information about the Python-list