this is a polynomial class
class Polynomial(object):
def __init__(self, polynomial):
self.p = tuple(polynomial)
def get_polynomial(self):
return self.p
def __neg__(self):
return tuple([tuple([-i[j] if j==0 else i[j] for j in range(len(i))])for i in self.p])
def __add__(self, other):
pass
def __sub__(self, other):
pass
def __mul__(self, other):
pass
def __call__(self, x):
pass
def simplify(self):
pass
def __str__(self):
return 'something'
if i use the below code, i am getting error that -p has syntax error. is there a different way to override the magic methods ?
p = Polynomial([(2, 1), (1, 0)])
print p
print p.get_polynomial()
q = ‑p; q.get_polynomial()
i am getting syntax error at q = -p