June 2001
Intermediate to advanced
416 pages
10h 24m
English
Inheritance is a mechanism for creating a new class that specializes or modifies the behavior of an existing class. The original class is called a base class or a superclass. The new class is called a derived class or a subclass. When a class is created via inheritance, it “inherits” the attributes defined by its base classes. However, a derived class may redefine any of these attributes and add new attributes of its own.
Inheritance is specified with a comma-separated list of base-class names in the class statement. For example:
class A: varA = 42 def method1(self): print "Class A : method1" class B: varB = 37 def method1(self): print "Class B : method1" def method2(self): print "Class B : method2" class C(A,B): # Inherits from ...
Read now
Unlock full access