码迷,mamicode.com
首页 > 编程语言 > 详细

python多继承简单方法

时间:2018-09-10 11:00:37      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:ati   方法   end   money   tin   一个   name   ini   man   

class people(object):  #建创一个人类
def __init__(self,name,age):
self.name = name
self.age = age
def eat(self):
print("%s is eatint‘‘‘‘‘" % self.name)
def talk(self):
print("%s is talking......" % self.name)
def sleep(self):
print("%s is sleeping" % self.name)
class Relation(object): # 创建一人交朋友类
def make_friends(self,obj):
print("%s is making friends %s" %(self.name,obj.name))

class Man(people,Relation):#男人类 多继承,又继承交朋友类
def __init__(self,name,age,money):
#people.__init__(self,name,age)
super(Man,self).__init__(name,age)
self.money = money
print("%s 一出生就有 %s money..." % (self.name,self.money))

def piao(self):
print("%s is piaoing....20s...done." % self.name)
def sleep(self):
people.sleep(self)
print("man is sleeping")
class Woman(people,Relation):#女人类 继承交朋友和人类 多继承
def get_birth(self):
print("%s is born a baby" % self.name)
m1 = Man("zy",22,10)
m1.eat()
w1 = Woman("cxh",25)
m1.make_friends(w1)


python多继承简单方法

标签:ati   方法   end   money   tin   一个   name   ini   man   

原文地址:https://www.cnblogs.com/fgxwan/p/9617203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!