相关疑难解决方法(0)

使用@property与getter和setter

这是一个纯Python特定的设计问题:

class MyClass(object):
    ...
    def get_my_attr(self):
        ...

    def set_my_attr(self, value):
        ...
Run Code Online (Sandbox Code Playgroud)

class MyClass(object):
    ...        
    @property
    def my_attr(self):
        ...

    @my_attr.setter
    def my_attr(self, value):
        ...
Run Code Online (Sandbox Code Playgroud)

Python让我们可以这样做.如果你要设计一个Python程序,你会使用哪种方法?为什么?

python properties getter-setter

711
推荐指数
13
解决办法
41万
查看次数

标签 统计

getter-setter ×1

properties ×1

python ×1