class ClassName:
__privt = 50 # 私有变量
a = ClassName()
# 私有变量外界无法访问
print(a.__privt) # AttributeError: 'ClassName' object has no attribute '__privt'
print(a._ClassName__privt) # 50 强制访问私有变量(加前缀 _ClassName )
class ClassName:
__privt = 50 # 私有变量
a = ClassName()
# 私有变量外界无法访问
print(a.__privt) # AttributeError: 'ClassName' object has no attribute '__privt'
print(a._ClassName__privt) # 50 强制访问私有变量(加前缀 _ClassName )