Inheritance/Polymorphism in Object Oriented Programming | Python for Beginners | Code with Kylie #10
ฝัง
- เผยแพร่เมื่อ 6 ก.พ. 2025
- We are LEVELING UP our object oriented programming. Once you start creating objects in Python using classes, you can step up your OOP game by incorporating inheritance and polymorphism!
Inheritance is when you can create child classes that inherit attributes and functions from the parent. These are often used when you have a more general overarching class but want to define more specific classes that may be similar but not quite the same. We do this in order to avoid copy-and-pasting a gazillion times.
In this video, we use dogs as an example of how inheritance can be used. I demonstrate how to create a parent class (superclass) and child class (subclass), and initialize both of them.
We can also have multiple inheritance, which is when a subclass can have multiple parents and inherits the unique functions and attributes of both of them. An example is a golden doodle!
Polymorphism is related to inheritance. Polymorphism means taking many forms. In OOP, this is often related to subclasses that override the parent method so that the more specific class might follow a different set of instructions. In my example, I use different barks of different breeds of doggos.
In practical terms, I've used this in past projects to account for the slight differences in the subclasses. For example, if we are calculating cost of an object, maybe one subclass is set in the US, and another class is specific to France.. we would use the subclass to change from dollars to euros in the France subclass and add an extra layer. We could do this with if-statements, but they might grow repetitive and confusing. Polymorphism is a cleaner way to implement something like this.
Relevant links for more:
thepythonguru....
Inheritance vs polymorphism - www.geeksforge...
Feel free to leave any questions.
Please consider subscribing if you liked this video: www.youtube.co...
Thanks for watching everyone!
~~~~~~~~~~~~~~~~~~~~~~~~
Follow me on Instagram: / kylieyying
Follow me on Twitter: / kylieyying
Check out my website: www.kylieying.com
Thanks for watching :)
Some good additional resources if you want to read more!
thepythonguru.com/python-inheritance-and-polymorphism/
www.geeksforgeeks.org/difference-between-inheritance-and-polymorphism/
Follow me on Twitter and Instagram: @kylieyying
Thanks kylie!’ So whats next?
Good question.. I have a couple of directions - I want to do more tutorials and stuff, seems like most people want to see those. I also want to start talking about my research, make some videos that are less educational and more just about what you can do with CS. I want to inspire others!
Kylie Ying sounds great! Would love to hear more about your research
I like it when you say "Arf arf!"
Even my trainer was not able to make us understand that in 2 days, What you did in approx. 12 minutes.
You have some serious skills!!
Best of luck for future!!!! :)
Who in the world would dislike this video? She is amazing and used doggies for the example.
People who dislike this video are cute dog haters :)
Yeah, I like doggy stuff as well, if you know what I mean)
@@ИванПетрович-г6ю Now I don’t see it the same way lmao
Yeah.She's also cute. I want a programmer gf☺
@@FrancisCo-xk6rv oop
I have been through a full stack developer bootcamp, and months of self-study. After watching this video, I finally feel like I REALLY understand Inheritance and Polymorphism. Great examples! Thank you!
this video straight up taught me what 2 hours of stackoverflow answers and google searches could not. Thank you tons!! gave the explanation straight up w coherent examples. fire
I found Polymorphism a difficult concept to understand but after watching this video, I understood it perfectly well. Thnx for uploading great free content
very clear video that allowed an old French man like me to finally understand polymorphism . Merci !
OMG this is like the best video in explaining inheritance and polymorphism. So basically for inheritance you just include the name of parent class in the bracket of the subclass, then for polymorphism is just the idea of defining a method that's already present in the parent class but with different content.
Clear, concise, pacey video and so helpful on these core concepts of OOP - deserves MANY more views! Thank you!
It's the third time that I come back to this video to brush up on my knowledge of Python inheritance! Thanks for this amazing video.
Best Example I have ever come across and I wish everybody to use Doggo examples 💖
This video was EXACTLY what I was looking for when trying to practice these concepts. Thank you so much
Was looking for someone who could explain this in a simple way, and found you after multiple trials of other sources. You just won a student, and I consider myself the privileged one here. Thanks a bunch.
Good job Kylie!
Note:
You don't need to cal the parent class's __init__ from the child class's __init__ if the child doesn't introduce any new attributes
whoaa. ur so good at explaining everything in just a span of minutes. thank u so much. more videos like this, please
I’m learning abit of python everyday and I’m really loving your videos! Super easy to understand and well explained!!
Thank you soo much!! 🙏
I wish all programming videos on TH-cam were this quality
SUPER NICE KYLIE!!
THANK YOU. Like the tone and pace of your voice. Easy to digest. Very precise and succinct as well. Subbed. ✌️
I was confused between the two but now I know the difference, thanks!
Thanks for sharing the knowledge. It will now be a stepping stone for me. thanks a lot once again
damnn this video was 100x better than I had thought it would be. Deserved a like for sure. Thanks!
Nice!
hey man
you also having doupt in opps ............ omg💥💣
i am one of your subscriber and fan of your coding skills 😍
Thank you so much, you explained this in a super easy to understand way!
Your explanation of each of these topics was extremely clear and easy to understand! Excellent work. Also love the doggos
The best explanation I've got on these subjects
Thank you so much! Kylie!!! your examples on dog are wonderful!!
Multiple videos watched on this topic and still couldn't understand because of all the jargon they used. Good video and thanks
Great work Kylie. Your Python series is well explained and the examples you use make your videos more interesting.
This video is exactly what I was looking for! You explain the concepts so clearly and using doggos really helps me to understand 🤣 thank you!
print("Thank you. You made it very clear with examples and I now understand the concept.")
This is a fantastic video with a very simple and straight forward example - keep up the good work!
Thank you Kylie for such clear explaination using cute examples :)
Thanks Kylie I am really enjoying your pet programming
Seeing the word 'doggo' used in your variable name made me scroll down from the video just to hit the like button. Also, thanks for explaining the concepts clearly!
Great video, thank you so much! I was completely tripped up on the connection between a sub __init__ and super().__init__ and it makes complete sense now. Also I love the dog examples!
These were awesome watched all within a few days!
So much clear explanation...
We expect more videos like this...
Most simple explanation of Polymorfism I've seen so far :) Better than with build in dunder method usual examples.
Glad it helped! Actually I gave a bad example I think. Usually when a child class has two parent classes, you dont want the "grandparent" class to be the same. Probably shouldve made a "Pet" class or something
Excellent use of simple examples to explain inheritance and polymorphism :)
best tutorial, loved the doggo examples thnx
Best example!! Thank you!
I want to know in case of multiple inheritance if both parent class has same function
For instance let's say a function named dog_color() for one parent class it's white and other parent class it's black then what will the child class will display when we call
child_dog.dog_color()
Is it going to be black or white?
Thankyou so much kylie.. ❤🧚♀️for the wonderful explanation
Very good explanation..keep it up
Love you ❤
You explain wonderfully! Thanks!
I really like how you explained everything... keep up the great work, and keep teaching! I like your format quite a lot. :)
This was so cute. I love it. In my class, we kept using cats but I'm a dog person. lol
thanks queen love the dog examples
will you make more videos? I am eagerly waiting. You are so articulate and very good speaker with clarity in voice.
Thanks very much, explained much better than my uni!
Kylie, these videos are so good. They have really helped me a lot.
keep uploading more videos.absolutely amazing.keep up the good work
Thank you for your great tutorial video... Please create more python tutorials for beginner...
Amazing , glad that I found it . Good job and thank you
How can I like this video more than one time?🧠
I really like your teaching although it took me twenty years of teaching to understand that not all students are as smart as you think and see the world, I mean other videos, they are great, really is helping me , but the first time I was not ready and somehow intimidated , and there is nothing in the world for me that I can't understand so I learned more and get back and we squerd
You deserve a credit for those amazing videos :D Thanks so much
Excelente!
Thanks for the video, you explained it really well. I am trying to get my head around OOP, this sure did help. The only issue I can say is that you didn't mention a pug 🤣😝
I like her cute little ponytail!!
Kylie you're super amazing 💪😊
Wonderful explanation!
Very late comment but this video is absolutely amazing. Concise explanation given in an easy to digest manner. Thank you very much.
Great video.
great video Kylie - so helpful
This video was execellent
Thanks love this was really helpful
Awesome lesson! Very clearly explained. Thank you so much!
thank you so much! much easier to understand than my prof
Wow! Thank you very much! That was a mater class @Kylie Ying
thankyou so much kylie
Hi Kylie, I just find you, and I am big fun you and programming, can i ask you to make a video about your journey that how did you get expert in programming? any idea to help me to start getting better in coding please. Also, this tutorial just help with my assignment. Thanks. Well done
Thank you so much ♥️♥️♥️♥️ you're the best
Thank you for this great video! Helped me a lot.
10 out of 10
Thank you Mulan!
Thanks for your excellent explanation!
Great tutorial!
Seriously, best explanation ever :)
@Kylie Ying Why not make "Dog" an abstract class?
Thank you, you are really good at explaining and your examples are super helpful!!
Thanks for great explanation. U deserve more subs :D
thank you sooo soo much! you explain it so easily and in an interesting way.
that was clear!
Sorry if this is a bit of a dumb question; is it possible to inherit some information but not all? let’s say the Poodle has shed_value = 0 but the Golden Retriever has a shed_value = 5.
is there a way to make the Golden doodle class to inherit JUST the 0 value or the 5?
Omg! Watching make sense in seconds where if I'd just continue reading it on code cademy then it'll take 5x longer and even that I'd probably would still be confused 😅
same lol
code academy's written explanation was garbage
you saved me! thank you so much 💓
you didn't need to copy the def __init__ for all child classes right? Inheritance sorts that out if you don't re-define it no? Or was there something in the super() that made it different?
I'm brand new to python btw
Amazing. It really helps
Very nice video. 🙏
Nice content!
Woof! Woof!
why do we need the super class code here? I thought that by assigning dog as parent of the three lower classes then the three lower classes could use anything in the parent class with no further ado. No?
Thanks for the vid Kylie!
Thank you so much!!
Subscribed!
Kind of a newbie question from a newbie, but why do you have to use __init__? It seems to work without. What's the point of __init__?
great video, thank you!
Is that compiler VS Code or Pycharm?