美文网首页
下划线重写

下划线重写

作者: lkning | 来源:发表于2017-12-26 19:02 被阅读0次
    a. 对象加减乘除
        class Foo(object):
            
            def __init__(self,age):
                self.age = age
                
            def __add__(self, other):
                # return self.age + other.age
                return Foo(self.age + other.age)
                
        obj1 = Foo(19)
        obj2 = Foo(18)

        obj3 = obj1 + obj2

相关文章

网友评论

      本文标题:下划线重写

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