__str__ is tried first for user-friendly displays : str « Class « Python Tutorial






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



class addstr(adder): 
    def __str__(self):                         
        return '[Value: %s]' % self.data       

x = addstr(3) 
x + 1 
x                                              

print x                                        

str(x), repr(x)








11.28.str
11.28.1.Creating and accessing object attributes
11.28.2.__str__ is tried first for user-friendly displays