class implementation

88888 Dihedral dihedral88888 at gmail.com
Tue Oct 1 03:01:01 EDT 2013


On Tuesday, October 1, 2013 3:34:08 AM UTC+8, Dave Angel wrote:
> On 30/9/2013 08:41, markotaht at gmail.com wrote:
> 
> 
> 
> > under variables, i mean, the int's and lists and strings and floats that the parent class uses. IF in parent class there is variable called location, then can i use the same variable in my sub class.
> 
> 
> 
> Python doesn't actually have variables, but the things it documents as
> 
> variables are local names within a method.  Those are not visible
> 
> outside of the method, regardless of whether you're in a class or a
> 
> subclass.
> 
> 
> 
> But perhaps you mean attributes.  There are both class attributes and
> 
> instance attributes, and the behavior is quite different.  Roughly
> 
> speaking a class attribute occurs only once per class, and all code can
> 
> read its value with either Class.my_attrib   or  instance.my_attrib.  It
> 
> can be written with Class.my_attrib.
> 
> 
> 
> On the other hand, instance attributes are usable by 
> 
> instance.my_attrib, regardless of whether the instance is a base class
> 

An instance is an object of some class
that could have its own attributes
i.e. instance priviate properties
during the run time.

> or a child class.  Each instance of the class gets a separate copy of
> 
> such an attribute.  They are normally defined in the __init__() method.
> 
> 
> 
> If you don't happen to know the difference between a class an an
> 
> instance of that class, then all the above will look like gibberish, and
> 
> you need to do some studying first.
> 
> 
> 
> -- 
> 
> DaveA




More information about the Python-list mailing list