class sclass()
def display(self):
print('current value=%s'% self.data)
class class3(sclass):
#初始化属性值
def __init__(self,value):
self.data=value
#"+"运算符重载
def __add__(self,other):
return class3(self.data+other)
#打印对象
def __str__(self):
return 'class3:%s'% self.data
def mul(self,other):
self.data*=other
a=class3("abc")
a.display()
print(a) #调用__str__方法
b=a+" xyz" #调用__add__方法
b.display()
print(b)
a.mul(3)
print(a)
转载请注明原文地址: https://ju.6miu.com/read-667125.html