__repr__ and __str__ Return String Representations : repr « Class « Python Tutorial






class adder: 
    def __init__(self, value=0): 
        self.data = value                     
    def __add__(self, other): 
        self.data += other                    

class addrepr(adder):                         
    def __repr__(self):                      
        return 'addrepr(%s)' % self.data     

x = addrepr(2)                               
x + 1                                        
x                                            

print x                                      
str(x), repr(x)








11.26.repr
11.26.1.__repr__ method should return a string that could be used as executable code to re-create the object
11.26.2.__repr__ and __str__ Return String Representations