运算符

2020-11-22  本文已影响0人  木子李007
class mystr(int):
    def __add__(self,other):  # +
        return super().__add__(other).__add__(1).__add__(80)
    def __sub__(self,other):  # -
        return super().__sub__(other)
    def __mul__(self,other):  # *
        return super().__mul__(other)
    def __truediv__(self, other):  # /
        return super().__truediv__(other)

a = mystr(20)
b = mystr(10)
print(a+b)   # 111 a+b+1+80
print(a-b)   # 10
print(a*b)   # 200
print(a/b)   # 2.0
上一篇 下一篇

猜你喜欢

热点阅读