class FirstClass: def setdata(self, value): self.data = value # self is the instance def display(self): print self.data # self.data: per instanceclass SecondClass(FirstClass): # inherits setdata def display(self): # changes display print 'Current value = "%s"' % self.dataclass ThirdClass(SecondClass): def __init__(self, value): self.data = value def __add__(self, other): # on "self + other" return ThirdClass(self.data + other) def __mul__(self, other): self.data = self.data * other # on "self * other" a = ThirdClass("abc") # new __init__ calleda.display() # inherited methodb = a + 'xyz' # new __add__: makes a new instanceb.display()a * 3 # new __mul__: changes instance in-placea.display()
Name (required)
email (will not be published) (required)
Website