标签:elf div style hot class code ret 访问 otf
1 class Person: 2 __name = ‘hotfeng‘ 3 def getName(self): 4 return self.__name
__name是Person类的私有变量,要访问此私有变量,有两种方法:
1、p = Person()
print(p._Person__name)
2、p = Person()
print(p.getName())
Python的私有变量(__varName)是伪私有,其实是将__varName改写为了_ClassName__varName
标签:elf div style hot class code ret 访问 otf
原文地址:http://www.cnblogs.com/hotfeng/p/7794110.html