すぐに学ぶ:https://edu.csdn.net/course/play/24797/282190?utm_source=blogtoedu
class TestProprty:
def __init__(self, width, height):
self.width = width
self.height = height
def getmianji(self):
print(self.width * self.height)
def setdaxiao(self, size):
self.width = size[0]
self.height = size[1]
def getdaxiao(self):
return self.width, self.height
mianji = property(fget=getmianji, doc='获得面积')
daxiao = property(fget=getdaxiao, fset=setdaxiao, doc='获得大小')
tp = TestProprty(3, 4)
tp.mianji
print(tp.daxiao)
tp.daxiao = (7, 8)
tp.mianji
print('_' * 50)
class TestProprty2:
def __init__(self, width, height):
self.width = width
self.height = height
@property
def mianji(self):
print(self.width * self.height)
@property
def daxiao(self):
return self.width, self.height
@daxiao.setter
def daxiao(self, size):
self.width = size[0]
self.height = size[1]
tp = TestProprty2(4, 6)
tp.mianji
print(tp.daxiao)
tp.daxiao = (6, 7)
tp.mianji