Class operator add: instance + noninstance and noninstance + instance : Class radd : Class : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  Class   » [  Class radd  ]  Screenshots 
 



Class operator add: instance + noninstance and noninstance + instance



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

print x + y                # __add__:  instance + instance


           
       
Related examples in the same category
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.