Discuss / Python / 菜鸟教程,csdn,廖大一起看 了解差不多清楚, 光看这个有点懵逼

菜鸟教程,csdn,廖大一起看 了解差不多清楚, 光看这个有点懵逼

Topic source

tycoonBrain

#1 Created at ... [Delete] [Delete and Lock User]

#请利用@property给一个Screen对象加上width和height属性,以及一个只读属性resolution:

class Screen:

    @property

    def resolution(self):

        return self.width*self.height

# 测试:

s = Screen()

s.width = 1024

s.height = 768

print('resolution =', s.resolution)

if s.resolution == 786432:

    print('测试通过!')

else:

    print('测试失败!')


  • 1

Reply