[Tutor] Question about Dictionaries

Steven D'Aprano steve at pearwood.info
Tue Aug 17 02:24:30 CEST 2010


On Tue, 17 Aug 2010 09:12:39 am Huy Ton That wrote:
> What do you mean by subclass?

It's a fundamental term from object-oriented programming.

If you have a class that defines certain data and behaviour, you can 
create a *subclass* that inherits the same data and behaviour, except 
for specific examples which are over-ridden or over-loaded.

A simple example:

class MyInt(int):  # creates a subclass of int
    def __str__(self):
        return "My Integer %d" % self


MyInts are exactly the same as built-in ints except their string form is 
different.

>>> n = MyInt(42)
>>> print n
My Integer 42


-- 
Steven D'Aprano


More information about the Tutor mailing list