#global variable
_test__x=13
class test:
def __init__(self,x):
self.__x=x
def rex(self):
return __x
d = test(5)
print(d.rex())
Run Code Online (Sandbox Code Playgroud)
如果我运行此代码,它将返回 13 我知道解释器应用了名称修饰,因此变量__x变成了_test__x
但这与全局变量相同。
我尝试使用,self._test__x但没有用
如何访问__x声明的变量__init __.py而不是全局变量?