Hi All,
I am completely new to python programming language.I was trying to write a program on class.But I am getting this error.Can someone please help me to solve the error I am facing.I am using python2.5.
This is exactly what I wrote and still came up with this error
>>> p1 =point(3,4)
>>> p2 = point(5,3)
>>> print p1._add_(p2)
<__main__.poi nt instance at 0x0117ED28>
>>> p3 = p1+p2
Traceback (most recent call last):
File "<pyshell#301>" , line 1, in <module>
p3 = p1+p2
TypeError: unsupported operand type(s) for +: 'instance' and 'instance'
I am completely new to python programming language.I was trying to write a program on class.But I am getting this error.Can someone please help me to solve the error I am facing.I am using python2.5.
This is exactly what I wrote and still came up with this error
Code:
class point: def __init__(self,x=0,y=0): self.x=x self.y=y def _str_(self): return '('+ str(self.x)+', ' + str(self.y) + ')' def _add_(self,other): return point(self.x+ other.x,self.y+other.y)
>>> p2 = point(5,3)
>>> print p1._add_(p2)
<__main__.poi nt instance at 0x0117ED28>
>>> p3 = p1+p2
Traceback (most recent call last):
File "<pyshell#301>" , line 1, in <module>
p3 = p1+p2
TypeError: unsupported operand type(s) for +: 'instance' and 'instance'
Comment