__repr__ and __str__ Return String Representations : Repr : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Repr »

 

__repr__ and __str__ Return String Representations


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)



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Class
» Repr