#私有方法的定义与调用 class Cat: def __init__(self): self.name = "" self.age = 0 def __changeage(self,_age): self.age = _age def setage(self,_age): if _age < 0: #私有方法的调用 self.__changeage(10) else: self.__changeage(_age) def __str__(self): return "age is %d ."%(self.age) tom = Cat() tom.setage(11) #tom.__changeage(13) print(tom) tom.setage(-10) print(tom)
原文:https://www.cnblogs.com/zhanggaofeng/p/9536463.html