Discuss / Python / 为什么一定设setter,而不能直接通过获取后直接运算??

为什么一定设setter,而不能直接通过获取后直接运算??

Topic source

[?]

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

class Screen(object):

    def resolution(self):

        return self.width * self.height

s = Screen()

s.width = 1024

s.height = 768

print(s.resolution)

#运算结果:<bound method Screen.resolution of <__main__.Screen object at 0x00000183DAE87880>>


  • 1

Reply