一个从多个父类继承过来的子类,可以访问所有父类的功能。
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 著
原文:https://www.cnblogs.com/brightyuxl/p/8824801.html