Operator Overloading Basics
Mohit Bhatt
Mohit.Bhatt at grapecity.com
Mon Aug 28 11:55:18 EDT 2006
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 = value
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060828/cd56efe3/attachment.html>
More information about the Python-list
mailing list