对象的加减乘除

class Foo():
    def __init(self,age):
        self.age = age
    def __add__(self,other):
        return Foo(self.age + other.age)

obj1 = Foo(20)
obj2 = Foo(21)
obj3 = obj1+obj2

 

posted @ 2017-12-28 09:24  TAMAYURA  阅读(184)  评论(0编辑  收藏  举报