Inheritance

Specification

     class A:
        varA = 42
        def method1(self):
            print "Class A: method1"
     
     class B(A):         # Inherits from class A
        varB = 37
        def method2(self):
            print "Class B: method2"

Use

  • It works just like you would expect
     b = B()
     b.method2()       # Invokes B.method2()
     b.method1()       # Invokes A.method1()
     print b.varA      # Outputs '42' 
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 96
July 17, 2000, beazley@cs.uchicago.edu
>>>