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('Bad type')

        else:

            self._with=value

    @property  # 读高度度

    def height(self):

        return self._height

    @height.setter

    def height(self, value):

        if not isinstance(value, int):

            raise TypeError('Bad type')

        else:

            self._height = value

    @property

    def resolution(self):

        return self._height*self._with


  • 1

Reply