SlideShare a Scribd company logo
2
Most read
3
Most read
Multiple Inheritance
Damian Gordon
Multiple Inheritance
• A subclass can inherit from multiple superclasses, and have the
functionality of all of those superclasses available to it.
• This is called Multiple Inheritance.
• It sounds simple, and it is simple, but it is considered a very
tricky to implement in a clear way.
Multiple Inheritance
• The simplest and most useful form of multiple inheritance is
called a mixin.
• A MIXIN is a class that is specifically created to be a superclass
that other classes will inherit methods and attributes from.
• Let’s look at an example:
Multiple Inheritance
• Let’s say we want to add functionality to our Contact class,
to allow us to send an e-mail to self.email.
• Sending an e-mail is a sufficiently general task that many other
classes might use it also.
• Let’s look at the MIXIN class for e-mailing:
Multiple Inheritance
class MailSender:
def send_mail(self, message)
print(“Sending mail to ” + self.email)
# e-mail logic here
# END send_mail.
# END class.
Multiple Inheritance
• So now we can create a new class that uses both Contact
and our new class MailSender
class EmailableContact(Contact,MailSender):
# Do stuff
# END class.
Multiple Inheritance
• So defining a class that uses multiple inheritance works a lot
like calling a method with a number of parameters. We can
test the new program with the following:
>>>e = EmailableContact(“John Smith”, “jsmith@Company.com”)
>>> e.send_mail(“Hello, test email”)
Sending mail to jsmith@Company.com
etc.

More Related Content

What's hot (20)

PPTX
Packages In Python Tutorial
Simplilearn
 
PPTX
Python programming: Anonymous functions, String operations
Megha V
 
ODP
Python Modules
Nitin Reddy Katkam
 
PPT
Java collections concept
kumar gaurav
 
PPTX
Static keyword ppt
Vinod Kumar
 
PPTX
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Python set
Mohammed Sikander
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Properties and indexers in C#
Hemant Chetwani
 
PPTX
Templates in c++
ThamizhselviKrishnam
 
PPTX
Multithreading in java
Arafat Hossan
 
PPTX
Object oriented programming in python
nitamhaske
 
PDF
Object oriented approach in python programming
Srinivas Narasegouda
 
PPTX
Object Oriented Programming in Python
Sujith Kumar
 
PDF
Python exception handling
Mohammed Sikander
 
PPTX
Type casting in java
Farooq Baloch
 
PPTX
Arrays in java
Arzath Areeff
 
PPTX
Oop c++class(final).ppt
Alok Kumar
 
PPTX
Functions in Python
Shakti Singh Rathore
 
Packages In Python Tutorial
Simplilearn
 
Python programming: Anonymous functions, String operations
Megha V
 
Python Modules
Nitin Reddy Katkam
 
Java collections concept
kumar gaurav
 
Static keyword ppt
Vinod Kumar
 
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
Python set
Mohammed Sikander
 
Classes, objects in JAVA
Abhilash Nair
 
Properties and indexers in C#
Hemant Chetwani
 
Templates in c++
ThamizhselviKrishnam
 
Multithreading in java
Arafat Hossan
 
Object oriented programming in python
nitamhaske
 
Object oriented approach in python programming
Srinivas Narasegouda
 
Object Oriented Programming in Python
Sujith Kumar
 
Python exception handling
Mohammed Sikander
 
Type casting in java
Farooq Baloch
 
Arrays in java
Arzath Areeff
 
Oop c++class(final).ppt
Alok Kumar
 
Functions in Python
Shakti Singh Rathore
 

Viewers also liked (12)

PPTX
Object-Orientated Design
Damian T. Gordon
 
PPTX
Python: The Iterator Pattern
Damian T. Gordon
 
PPTX
Introduction to Python programming
Damian T. Gordon
 
PPTX
Python: Basic Inheritance
Damian T. Gordon
 
PPTX
Python: Design Patterns
Damian T. Gordon
 
PPTX
Python: Access Control
Damian T. Gordon
 
PPTX
Python: Third-Party Libraries
Damian T. Gordon
 
PPTX
Python: Polymorphism
Damian T. Gordon
 
PPTX
Python: Manager Objects
Damian T. Gordon
 
PPTX
Creating Objects in Python
Damian T. Gordon
 
PPTX
Python: Migrating from Procedural to Object-Oriented Programming
Damian T. Gordon
 
PPTX
The Extreme Programming (XP) Model
Damian T. Gordon
 
Object-Orientated Design
Damian T. Gordon
 
Python: The Iterator Pattern
Damian T. Gordon
 
Introduction to Python programming
Damian T. Gordon
 
Python: Basic Inheritance
Damian T. Gordon
 
Python: Design Patterns
Damian T. Gordon
 
Python: Access Control
Damian T. Gordon
 
Python: Third-Party Libraries
Damian T. Gordon
 
Python: Polymorphism
Damian T. Gordon
 
Python: Manager Objects
Damian T. Gordon
 
Creating Objects in Python
Damian T. Gordon
 
Python: Migrating from Procedural to Object-Oriented Programming
Damian T. Gordon
 
The Extreme Programming (XP) Model
Damian T. Gordon
 
Ad

Similar to Python: Multiple Inheritance (13)

PPTX
Multiple inheritance
zindadili
 
PPTX
full defination of final opp.pptx
rayanbabur
 
PDF
Multiple Inheritance
adil raja
 
PPTX
object oriented programming unit two ppt
isiagnel2
 
PPTX
Object oriented programming
Saiful Islam Sany
 
PPTX
Java interfaces
Stavros Antifakos
 
PPTX
Pi j3.1 inheritance
mcollison
 
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
PPTX
C++ programming introduction
sandeep54552
 
PPTX
29c
Sireesh K
 
PPTX
29csharp
Sireesh K
 
PPTX
) Function overriding, Member Classes Nesting of Classes.pptx
sachinkumar541404
 
PPTX
Java OOPS Concept
Richa Gupta
 
Multiple inheritance
zindadili
 
full defination of final opp.pptx
rayanbabur
 
Multiple Inheritance
adil raja
 
object oriented programming unit two ppt
isiagnel2
 
Object oriented programming
Saiful Islam Sany
 
Java interfaces
Stavros Antifakos
 
Pi j3.1 inheritance
mcollison
 
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
C++ programming introduction
sandeep54552
 
29csharp
Sireesh K
 
) Function overriding, Member Classes Nesting of Classes.pptx
sachinkumar541404
 
Java OOPS Concept
Richa Gupta
 
Ad

More from Damian T. Gordon (20)

PPTX
Introduction to Prompts and Prompt Engineering
Damian T. Gordon
 
PPTX
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
PPTX
TRIZ: Theory of Inventive Problem Solving
Damian T. Gordon
 
PPTX
Some Ethical Considerations of AI and GenAI
Damian T. Gordon
 
PPTX
Some Common Errors that Generative AI Produces
Damian T. Gordon
 
PPTX
The Use of Data and Datasets in Data Science
Damian T. Gordon
 
PPTX
A History of Different Versions of Microsoft Windows
Damian T. Gordon
 
PPTX
Writing an Abstract: A Question-based Approach
Damian T. Gordon
 
PPTX
Using GenAI for Universal Design for Learning
Damian T. Gordon
 
DOC
A CheckSheet for Inclusive Software Design
Damian T. Gordon
 
PPTX
A History of Versions of the Apple MacOS
Damian T. Gordon
 
PPTX
68 Ways that Data Science and AI can help address the UN Sustainability Goals
Damian T. Gordon
 
PPTX
Copyright and Creative Commons Considerations
Damian T. Gordon
 
PPTX
Exam Preparation: Some Ideas and Suggestions
Damian T. Gordon
 
PPTX
Studying and Notetaking: Some Suggestions
Damian T. Gordon
 
PPTX
The Growth Mindset: Explanations and Activities
Damian T. Gordon
 
PPTX
Hyperparameter Tuning in Neural Networks
Damian T. Gordon
 
PPTX
Early 20th Century Modern Art: Movements and Artists
Damian T. Gordon
 
PPTX
An Introduction to Generative Artificial Intelligence
Damian T. Gordon
 
PPTX
An Introduction to Green Computing with a fun quiz.
Damian T. Gordon
 
Introduction to Prompts and Prompt Engineering
Damian T. Gordon
 
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
TRIZ: Theory of Inventive Problem Solving
Damian T. Gordon
 
Some Ethical Considerations of AI and GenAI
Damian T. Gordon
 
Some Common Errors that Generative AI Produces
Damian T. Gordon
 
The Use of Data and Datasets in Data Science
Damian T. Gordon
 
A History of Different Versions of Microsoft Windows
Damian T. Gordon
 
Writing an Abstract: A Question-based Approach
Damian T. Gordon
 
Using GenAI for Universal Design for Learning
Damian T. Gordon
 
A CheckSheet for Inclusive Software Design
Damian T. Gordon
 
A History of Versions of the Apple MacOS
Damian T. Gordon
 
68 Ways that Data Science and AI can help address the UN Sustainability Goals
Damian T. Gordon
 
Copyright and Creative Commons Considerations
Damian T. Gordon
 
Exam Preparation: Some Ideas and Suggestions
Damian T. Gordon
 
Studying and Notetaking: Some Suggestions
Damian T. Gordon
 
The Growth Mindset: Explanations and Activities
Damian T. Gordon
 
Hyperparameter Tuning in Neural Networks
Damian T. Gordon
 
Early 20th Century Modern Art: Movements and Artists
Damian T. Gordon
 
An Introduction to Generative Artificial Intelligence
Damian T. Gordon
 
An Introduction to Green Computing with a fun quiz.
Damian T. Gordon
 

Recently uploaded (20)

DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PDF
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PDF
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
PDF
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
PDF
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
PPTX
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
PDF
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
PPTX
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
PDF
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PPTX
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
Genomics Proteomics and Vaccines 1st Edition Guido Grandi (Editor)
kboqcyuw976
 
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
Quiz Night Live May 2025 - Intra Pragya Online General Quiz
Pragya - UEM Kolkata Quiz Club
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
Connecting Linear and Angular Quantities in Human Movement.pptx
AngeliqueTolentinoDe
 

Python: Multiple Inheritance

  • 2. Multiple Inheritance • A subclass can inherit from multiple superclasses, and have the functionality of all of those superclasses available to it. • This is called Multiple Inheritance. • It sounds simple, and it is simple, but it is considered a very tricky to implement in a clear way.
  • 3. Multiple Inheritance • The simplest and most useful form of multiple inheritance is called a mixin. • A MIXIN is a class that is specifically created to be a superclass that other classes will inherit methods and attributes from. • Let’s look at an example:
  • 4. Multiple Inheritance • Let’s say we want to add functionality to our Contact class, to allow us to send an e-mail to self.email. • Sending an e-mail is a sufficiently general task that many other classes might use it also. • Let’s look at the MIXIN class for e-mailing:
  • 5. Multiple Inheritance class MailSender: def send_mail(self, message) print(“Sending mail to ” + self.email) # e-mail logic here # END send_mail. # END class.
  • 6. Multiple Inheritance • So now we can create a new class that uses both Contact and our new class MailSender class EmailableContact(Contact,MailSender): # Do stuff # END class.
  • 7. Multiple Inheritance • So defining a class that uses multiple inheritance works a lot like calling a method with a number of parameters. We can test the new program with the following: >>>e = EmailableContact(“John Smith”, “[email protected]”) >>> e.send_mail(“Hello, test email”) Sending mail to [email protected]