_ClassName__privt

class ClassName:
    __privt = 50  # 私有变量

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

  

print(CounterList.__mro__)
(<class '__main__.CounterList'>, <class 'list'>, <class 'object'>)

posted @ 2023-12-13 23:13  sangern  阅读(5)  评论(0编辑  收藏  举报