python中@property装饰器的用法

来源:互联网 发布:oracle数据库入门 编辑:程序博客网 时间:2024/05/17 07:01
Python中的@property可以将一个类中的方法当作属性来访问,尤其适合于作为可由用户读取但不能修改的API。class C:        @property    def foo(self):        return 1    def foo2(self):        return 2c=C()print(c.foo)#正确print(c.foo2)#报错
0 0
原创粉丝点击