python获取私有变量的方法

class fun(obj):

  def __init__(self):

    self.name="王"

    self.__age="10"

  def get(self):

    return self.__age

f = fun()

f.name = "老王"   #可以访问到实例变量,但是访问不到self.__age

print(f,get())   #可以通过这样获取到私有变量

print(f._fun__age)  #这样也可以访问到

原文地址:https://www.cnblogs.com/ojbk6943/p/14902203.html