无法从有关此主题的其他线程中得到直接答案:
在 Python 中,使用之间的主要区别是什么
class Foo(object):
def __init__(self, x):
self.x = x
Run Code Online (Sandbox Code Playgroud)
和
class Foo(object):
def __init__(self, x):
self._x = x
@property
def x(self):
return self._x
Run Code Online (Sandbox Code Playgroud)
从外观上看,以这种方式使用@property 会使 x 只读……但也许有人有更好的答案?谢谢/弗雷德