Hello,

I just started out with python( couple of weeks).

I have a query regarding Operator Overloading

 

class c1:

            def __init__(self,value):

                        self.data = "">

            def __add__ (self,operand2):

                        self.data += operand2

 

obj1 = c1(1)

obj1 + 10 # this works just fine

10 + obj1 # throws exception

 

Exception Details

Traceback (most recent call last):

  File "<pyshell#38>", line 1, in -toplevel-

    10+ obj1

TypeError: unsupported operand type(s) for +: 'int' and 'instance'

 

            Q. What do I have to do to make the following line work?

 

                        10 + obj1

 

Thanks and regards

Mohit

 

           

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to