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

阅读 98

2022-08-02

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)

0 0 举报