def add(a,b):
return a.value+b.value
class INT(object):
def __init__(self,value):
self.value=value
def __add__(self, other):
return self.value+other.value
class LIST(object):
def __init__(self,value):
self.value=value
a=INT(1)
b=INT(2)
list1=LIST([1,2])
list2=LIST([3,4])
print(add(a,b))
print(add(list1,list2))
python 多态
最新推荐文章于 2024-06-14 11:20:52 发布