alex_bn_lee

导航

【398】COMP9021 - Polynomial

构建 Polynomial 类,实现 +, -, *, / and +=, -=, *=, /=

参考:如何用python编程求解二元一次方程组。如x+y=3;x-y=1
参考:python对重载运算符的限制
参考:python:自定义对象的打印

operator overwrite
+
| \__add__ - | \__sub__ * | \__mul__ / | \__truediv__ += | \__iadd__ -= | \__isub__ *= | \__imul__ /= | \__itruediv__ 字符串打印 | \__str__

改写举例:

def __add__(self, other):
    ...
    return Polynomial(self.ex + other.ex)

def __iadd__(self, other):
    return Polynomial(self.ex) + Polynomial(other.ex)

posted on 2019-04-19 10:42  McDelfino  阅读(242)  评论(0编辑  收藏  举报