# age = ""
# height = 0
def run(self):
print("pao")
def chi(self,food):
print("%s吃%s"%(self.name, food))
#构造
def __init__(self, name, age, height):
self.name = name
self.age = age
self.height = height
self.__money = 5000 #访问限制
def SetMoney(self, num):
if num < 10000:
self.__money = 5000
else:
self.__money = num
#重写
def __str__(self):
return "name:%s age:%d money: %d"%(self.name, self.age, self.__money)
#析构
def __del__(self):
print("对象释放")
per1 = Person("tom",12,168)
print(per1.name)
per1.chi("apple")
per1.SetMoney(4)
print(per1)
原文:http://blog.51cto.com/victor2016/2060861