class FirstClass: # define a class object def setdata(self, value): # define class methods self.data = value # self is the instance def display(self): print self.data # self.data: per instance
class SecondClass(FirstClass): # inherits setdata def display(self): # changes display print 'Current value = "%s"' % self.data
z = SecondClass() z.setdata(42) # setdata found in FirstClass z.display() # finds overridden method in SecondClass
Related Scripts with Example Source Code in same category :