Python面向对象——多重继承

时间:2022-04-24 16:46:00

1本文的作用

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

2图文介绍

Python面向对象——多重继承

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 著