#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class Screen():
@property
def Width(self):
return self._width
@Width.setter
def Width(self,value):
if not isinstance(value, int):
raise ValueError('score must be an integer!')
if value <= 0:
raise ValueError('score must >0')
self._width=value
@property
def Heigth(self):
return self._heigth
@Heigth.setter
def Heigth(self,value):
if not isinstance(value, int):
raise ValueError('score must be an integer!')
if value <= 0:
raise ValueError('score must >0')
self._heigth=value
@property
def Resolution(self):
return str('%d * %d'%(self._width,self._heigth))
s=Student()
s.Width =1024#这里的Width不是属性名,是方法名,属性名是_width,可用dir(s)查看
s.Heigth =768#这里的Hidth不是属性名,是方法名,属性名是_hidth,可用dir(s)查看
s.Resolution #这里的Resolution不是属性名,是方法名,
早起的达先生