python多继承简单方法

Posted 法师-谢双元

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python多继承简单方法相关的知识,希望对你有一定的参考价值。

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多继承简单方法的主要内容,如果未能解决你的问题,请参考以下文章

(转)Python: super 没那么简单

python socket 实现简单client与server

Python爬虫编程思想(138):多线程和多进程爬虫--从Thread类继承

Python爬虫编程思想(138):多线程和多进程爬虫--从Thread类继承

python super()函数的用法与多重继承

python-多继承