【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)

猜你喜欢

转载自www.cnblogs.com/alex-bn-lee/p/10734465.html