标签:重写 str pre 访问 def elf __del__ ret class
class Person(object):# 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)
标签:重写 str pre 访问 def elf __del__ ret class
原文地址:http://blog.51cto.com/victor2016/2060861