# #Example of creating a simple class that includes # normal methods and "special" methods that redefine # the behavior of system operators. # class Complex: def __init__(self, R=0, I=0): self.r = R self.i = I def printRI( self, ): print self.r, "+ i", self.i def __add__(self, other): retVal = Complex() retVal.r = self.r + other.r retVal.i = self.i + other.i return( retVal) p = Complex(7,8) p2 = Complex(1,2) print "p is:", p.printRI( ) print "p2 is:", p2.printRI() p3 = p + p2 print "p3 is", p3.printRI()