初阶:
#面向对象的特征:封装,继承,多态
#初阶
class dog:
def __init__(self,name):
self.name = name
def bulk(self):
print("%s:wangwangwang!"%self.name)
d1 = dog("vergil")
d2 = dog("tanying")
d1.bulk()
d2.bulk()
#进阶
class role(object):
def __init__(self,name,sex,age,job,money = 10000):
self.name = name
self.sex = sex
self.age = age
self.job = job
self.money = money
def buy(self,something):
print("%s has bought a %s"%(self.name,something))
print("%s has %s in his hand"%(self.name,self.money))
def growth(self,newage):
print("%s has growth from %s to %s"%(self.name,self.age,newage))
def overview(self,high):
print("%s is a %s,and he is %s high"%(self.name,self.sex,high))
def drump(self,newjob):
print("%s has changed job from %s to %s"%(self.name,self.job,newjob))
vergil = role("vergil","male",25,"IT")
vergil.buy("cake")
vergil.growth(26)
vergil.overview(175)
vergil.drump("Financial software test")