class Screen(object):
def resolution(self):
return self.width * self.height
s = Screen()
s.width = 1024
s.height = 768
print(s.resolution)
#运算结果:<bound method Screen.resolution of <__main__.Screen object at 0x00000183DAE87880>>
@property 这个是读属性的装饰器,有这个的话,会直接返回属性值
Sign in to make a reply
[?]
class Screen(object):
def resolution(self):
return self.width * self.height
s = Screen()
s.width = 1024
s.height = 768
print(s.resolution)
#运算结果:<bound method Screen.resolution of <__main__.Screen object at 0x00000183DAE87880>>