下划线重写
2017-12-26 本文已影响0人
lkning
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