小编Con*_*101的帖子

在 Python 的构造函数中使用 self._variable 和只使用 self.variable 有什么区别

例如,如果我创建一个类 Point。

类点:

def__init__(self, x, y):
    self._x = x
    self._y = y 
Run Code Online (Sandbox Code Playgroud)

类点:

def__init__(self, x, y):
    self.x = x
    self.y = y 
Run Code Online (Sandbox Code Playgroud)

self._x 和 self.x 的使用有什么区别。

python class instance-variables

2
推荐指数
1
解决办法
1693
查看次数

标签 统计

class ×1

instance-variables ×1

python ×1