__repr__ method should return a string that could be used as executable code to re-create the object : Repr : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Repr »

 

__repr__ method should return a string that could be used as executable code to re-create the object


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



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

x = addboth(4
print x                                       
str(x), repr(x)



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Class
» Repr