Discuss / Python / property

property

classScreen(object):

@property

defwidth(self):

returnself._width

@width.setter

defwidth(self, value):

self._width = value

@property

defheight(self):

returnself._height

@height.setter

defheight(self, value1):

self._height = value1

@property

defresolution(self):

returnself._width *self._height

s = Screen()

s.width =1024

s.height =768

print('resolutio =', s.resolution)

if s.resolution ==786432:

print('通过')

else:

print('失败')


  • 1

Reply