0
点赞
收藏
分享

微信扫一扫

Python的私有属性的特殊访问方法

class Program(object):

def __init__(self,name,age,weigth):

self.name=name

self._age=age

self.__weight=weigth

def getWeight(self):

return self.__weight

if __name__ == '__main__':

a=Program("alex",23,45)

print a

print dir(a)

print a.getWeight()

print a._Program__weight#python 的私有属性的定义

举报

相关推荐

0 条评论