Discuss / Python / 老师最后一个断言怎么用的这个不是很了解 所以删除了

老师最后一个断言怎么用的这个不是很了解 所以删除了

Topic source
class Screen(object):

    @property
    def width(self):
        return self.__width
    @width.setter
    def width(self,value):
        if not isinstance(value,int):
            raise TypeError('Value must be an int!')
        self.__width = value

    @property
    def height(self):
        return self.__height
    @height.setter
    def height(self,value):
        if not isinstance(value,int):
            raise TypeError('Value must be an int!')
        self.__height = value
    @property
    def resolution(self):
        return ('%d * %d'%(self.__width,self.__height))

s = Screen()
s.width = 1024
s.height = 768
print(s.resolution)

  • 1

Reply