首页 > 编程语言 > 详细

python多继承简单方法

时间:2018-09-10 10:24:51      阅读:157      评论:0      收藏:0      [点我收藏+]
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多继承简单方法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!