__str__ is tried first for user-friendly displays : Str : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Str »

 

__str__ is tried first for user-friendly displays


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 + 
x                                              

print x                                        

str(x), repr(x)



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Str