Python Tutorial - 19. Multiple Inheritance
Key Takeaways
Demonstrates multiple inheritance in Python using class derivation
Full Transcript
hello and welcome to code Basics coding tutorial today we are going to cover multiple inheritance in Python uh in my last video we looked at uh single inheritance uh and we been through basic concepts in this one we are going to inherit a class uh from two different classes so as you see here uh I have defined two classes father and mother uh and father has one method gardening it just prints I enjoy gardening mother has uh one method called cooking now I'm going to define a child class from these two classes and the way you inherit your class from two classes is you specify just the class name in the bracket like this okay and that will uh inherit child class from from this Base Class number one and Base Class number two okay now you can say okay uh child what does child know so Sports so child will say okay I enjoy sports okay now as a standard example indicates child will inherit properties of father and mother so that's why now child will have access to to cooking and gardening method as well so when you create a child class object and if you say gardening it will allow it to access that method and then of course it can access its own method as well so let's run it and see what happens excellent so you can access so child class can access the method of both of of these base classes okay so the benefit of multiple inheritance is sometimes you have two different classes and you just want to inherit the properties and methods of those classes just to reuse the code and then you want to add your own customization so that's when you should use multiple inheritance and you can inherit your class from as many classes as you want so here after comma you can type any number of classes and it should work another way to look at uh multiple inheritance is you can even in a single method you can call the Base Class method so if I replace this method with let's say by calling just the skills so let's say father has skills of gardening and programming this father is a computer engineer by the way and mother has a skill of cooking and art okay now the name of the methods are same here child also has the same method call skills and child enjoy sports now when you run the program like this it will okay let me just remove all these calls C do skills when you run the program like this it will just print spots now if you want to inherit The Base Class skills method then you can just type in your class name here so father. skills and you can do mother do skills so what this will do is when it executes this method it will first execute father. skills method and mother. skills method and then it will print the statement so when you run it uh oh yeah it is complaining because you need to pass this self parameter in the bracket okay so it says Now gardening programming cooking and art so this child is a multi-talented personality now he has all the skills of his father which is gardening and programming all the skills of mother which is cooking and art and he has his own skills as well which is sports so that was all about multiple inheritance thank you for watching
Original Description
Video without background music: https://youtu.be/ttMX3Ns_0oY
This python tutorial help us to gain insights of multiple inheritances. Derivation of a class from more than one base class in python language is called as multiple inheritances. Create your own classes with the help of multiple inheritances in Python with this tutorial.
Topics that are covered in this Python Video:
0:00 Introduction
3:35 Inherit class from two different classes
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Code used in this tutorial: https://github.com/codebasics/py/blob/master/Basics/19_multiple_inheritance.py
Next Video:
Python Tutorial - 20. Raise Exception And Finally: https://www.youtube.com/watch?v=xiNbGFf_kD0&list=PLeo1K3hjS3usILfyvQlvUBokXkHPSve6S&index=22
Website: https://codebasics.io/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from codebasics · codebasics · 32 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
▶
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
Related Reads
📰
📰
📰
📰
AI Tool Scorecard: 5 Dimensions EU SMEs Miss Before Signing
Dev.to AI
Aplikasi AI Harian Untuk Produktivitas, Bye Burnout!
Medium · AI
From stethoscopes to source code:Why I Switched from Pre Med to BS AI
Medium · Programming
Ilios Software Pvt. Ltd.: Building Practical AI Products That Solve Real Problems
Medium · AI
🎓
Tutor Explanation
DeepCamp AI