__radd__ Handles Right-Side Addition : Radd : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Radd »

 

__radd__ Handles Right-Side Addition


class Commuter: 
    def __init__(self, val)
        self.val = val 
    def __add__(self, other)
        print 'add', self.val, other 
    def __radd__(self, other)
        print 'radd', self.val, other 

x = Commuter(88
y = Commuter(99

x + 1                           # __add__: instance + noninstance
+ y                           # __radd__: noninstance + instance
x + y                           # __add__: instance + instance



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Class
» Radd