您的位置:首页 > 编程语言 > Python开发

Python面向对象——多重继承

2018-04-13 23:38 357 查看

1本文的作用

一个从多个父类继承过来的子类,可以访问所有父类的功能。

2图文介绍



3代码验证

class Contact:
all_contacts = []

def __init__(self, name, email):
self.name = name
self.email = email
Contact.all_contacts.append(self)

class MilSender:
def send_mail(self, message):
print("Sending mail to " + self.email)

class EmailableContact(Contact, MilSender):
pass

e = EmailableContact("John Smith", "j@qq.com")

Contact.all_contacts

e.send_mail("Hello, test e-mail here.")


参考:本文参考学习《Python3 Object Oriented Programming》,根据自己理解改编,Dusty Phillips 著
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: