运算符

作者: 木子李007 | 来源:发表于2020-11-22 18:18 被阅读0次
    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
    

    相关文章

      网友评论

          本文标题:运算符

          本文链接:https://www.haomeiwen.com/subject/yezuiktx.html