class Programer(object):
hobby='Play Computer'
def _inint_(self,name,age,weight):
self.name=name
self._age=age
self.__weight=weight
def get_weight(self):
return self._weight
if __name__=='__main__':
programer=Programer('Albert',25,80)
print(dir(programer))
print(programer.__dict__)
print(programer.get_weight())
print(programer._Programer__weight)
执行完提示object() takes no parametersclass Programer(object):
hobby='Play Computer'
def __init__(self,name,age,weight):#init名字写错了
self.name=name
self._age=age
self.__weight=weight
def get_weight(self):
return self.__weight#这里的名字也漏了个下划线
if __name__=='__main__':
programer=Programer('Albert',25,80)
print(dir(programer))
print(programer.__dict__)
print(programer.get_weight())
print(programer._Programer__weight)
代码 第3行有问题: def_inint_(self,name,age,weight):
# __init__(self)是构造函数哦!
应该是: __definit__(self, name, age, weight):