Python OOP Tutorial 4: Inheritance - Creating Subclasses

preview_player
Показать описание
In this Python Object-Oriented Tutorial, we will be learning about inheritance and how to create subclasses. Inheritance allows us to inherit attributes and methods from a parent class. This is useful because we can create subclasses and get all of the functionality of our parents class, and have the ability to overwrite or add completely new functionality without affecting the parents class in any ways. Let's get started.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:

#Python
Рекомендации по теме
Комментарии
Автор

Corey talks about inheritance of classes in this video.


1. What is inheritence?
It is a method that allows us to create a new class that shares the same attributes and method with the original function, and add some extra functionality to the new class. It also does not disturb the original class.


2. How to make a class inherit from another class?
class Developer(Employee):


3. Structure of classes and subclasses.
When we input a function to a subclass, python follows the 'method resolution order', which is the chain of classes that it goes through to find what the method is. All classes have the built-in group of methods and attributes as their primary order.


4. How to initiate the subclass so that it can handle more information than its original class can?
There are 2 ways.
first, using the super method as follows and pass in the arguments in interest.
super.__init__()


Second, call the parent's init method explicitly and pass in the arguments in interest.
Employee.init(self, first, last, )


5. Useful tools when exploring the inheritance system.
.isinstance(instance, class)
This method returns the boolean value of whether an instance belongs to a calss
.issubclass(subclass, class)
This method returns the boolean value of whether a class has inherited from the second class.


6. Example of class inheritance
Whisky library

++ when setting a default value for an ungiven argument, avoid using an empty mutable data type. That's a topic for another video.

xcxfgpn
Автор

omg...it's like you are ansewring our questions before we even ask them..brilliant thank you very much

scorpp
Автор

One great thing about Corey's videos, you know it's safe to 'Like' them before you watch them! *lol*

MyTubeUtoo
Автор

I almost gave up on oop and then watched this series..The best playlist about oop.

rakeshkottu
Автор

Print(isinstance(Corey, Super_humans))

True

ShivamSingh-bxlg
Автор

I have used Treehouse and currently I'm attending programming bootcamp, but only you can explain stuff so clearly. Once again - thanks a lot

rogut
Автор

Your explanation and use of the terminology is flawless through these tutorials, and I can't begin to tell you how helpful that is!

Jonathan-odxc
Автор

2:45 - intro to Method resolution order and help(<class>) function
6:06 - inheritance and super().__init__()
10:50 - if attribute = None ... Else attribute
16:00 - isinstance(self, <class>) and issubclass(<subclass>, <class>)
17:36 - real world example

xluyyjhfg
Автор

Studying data science at college and went through this topic in class and felt completely lost. Your tutorials made it click so easily and with no issues. Very well done Corey !

MarioIuliano
Автор

Thanks Mr corey!!!From Kenya and youre basically my role model in your humble approach towards sharing knowldge with us...In my own way ill try help as many people in my vicinity...tell them code is not as difficult..just as you are teaching us to love code!!! Thnaks Corey!!!

calebmbugua
Автор

this cheeky man trying to give himself a bigger raise then the other employees

vinnyisntgud
Автор

I have a confession - more and more videos I see from this playlist, the more I am in awe at how Corey manages to explain that often-missed 'WHY' along explaining the 'how'. The 'how' explanation is already brilliant, but that 'WHY' on the top... He just brute-forces it to click!

hatani
Автор

I've done my share of research before stumbling across this lecture series.
Of all the Courses on Lynda, Udemy, and Coursera this is by far the best video tutorial I've come across.
Thanks a lot Corey!

vishwaskaupvijayananda
Автор

Corey, This is not at all a long video, it's simply a gem on Python inheritance

parijatbandyopadhyay
Автор

this is great, most people give such simple examples on youtube, that they undermine the purpose of having a class just to show you what you can do with it. That works if someone knows OOP very well, but for relatively new users its a mess. This is great stuff for me!

sebastianvbb
Автор

This Python OOP Tutorial playlist is super useful for everybody, hats off Corey Schafer, Subscribed and watching your other useful tutorials.

kvnptl
Автор

If teaching is an Art, this guy is the Picasso of it.

manakupadhyay
Автор

Honestly, the class tutorials are the best tutorials I have ever watched. You explain it in plain english, straight to the point and easy to understand. Thank you so much.

richardfriedrichsen
Автор

Definitely one of the best explanations of inheritance I've seen. This whole series has been great... I've been writing scripts and small procedural programs for years, but have only recently started using classes and sub-classes. I wish this series had been around when I first started trying to learn about class years ago.

jwolf
Автор

these explanations are beyond amazing. bought a course on udemy (best selling course to be specific) and what you have been able to explain to us in 6 videos has taken the course approximately 40 lectures!!!!

himansuodedra