[Tutor] Super class

Dave Angel davea at ieee.org
Fri Sep 25 12:39:31 CEST 2009


Katt wrote:
> As I am a beginner I am constantly assimilating new python code and vocabulary associated with it.
>
> Could someone please explain to me what a super class is, its importance and what level of python programming it is(beginner,intermediate,advanced programming technique)?
>
> This would greatly help me decide whether to try and wrap my brain around it or just skip the message.
>
> Thank you in advance,
>
> Katt
>   

It's an object oriented thing, and as such, "advanced programming."  (IMHO)

You use objects all the time in Python (int, string, def) , but building 
hierarchies of complex objects is an advanced technique.  The notion 
here is one of inheritance.  You write a class like the following:

class Myclass(object):
      description...

And this class derives from object, which is more-or-less the simplest 
class of all.  So object is the base class, and Myclass is the 
subclass.  If all classes were derived from object, we'd be done.  But 
you can also derive from a different class, and your code, and the code 
of your users, can get at the base class without needing to know what 
behavior comes from your sub class and which comes from the base.  The 
complexity comes when one subclass derives from nested base classes, or 
from a list of base classes, or both.

Superclass is a synonym for base class.  And super() is a mechanism you 
can use to specify one of your base classes without knowing all the 
classes that might be up there.

Incidentally, child class is a synonym for sub class as well.

DaveA



More information about the Tutor mailing list