Inheritance/Polymorphism in Object Oriented Programming | Python for Beginners | Code with Kylie #10

  Рет қаралды 73,266

Kylie Ying

Kylie Ying

3 жыл бұрын

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.com/python-inhe...
Inheritance vs polymorphism - www.geeksforgeeks.org/differe...
Feel free to leave any questions.
Please consider subscribing if you liked this video: kzbin.info?sub_...
Thanks for watching everyone!
~~~~~~~~~~~~~~~~~~~~~~~~
Follow me on Instagram: / kylieyying
Follow me on Twitter: / kylieyying
Check out my website: www.kylieying.com

Пікірлер: 180
@KylieYYing
@KylieYYing 3 жыл бұрын
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
@MrHorse16
@MrHorse16 3 жыл бұрын
Thanks kylie!’ So whats next?
@KylieYYing
@KylieYYing 3 жыл бұрын
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!
@MrHorse16
@MrHorse16 3 жыл бұрын
Kylie Ying sounds great! Would love to hear more about your research
@simbian4345
@simbian4345 2 жыл бұрын
I like it when you say "Arf arf!"
@vickkyphogat
@vickkyphogat 2 жыл бұрын
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!!!! :)
@pattyyy8071
@pattyyy8071 3 жыл бұрын
Who in the world would dislike this video? She is amazing and used doggies for the example.
@kaushikdr
@kaushikdr 3 жыл бұрын
People who dislike this video are cute dog haters :)
@user-em5ep9zw4z
@user-em5ep9zw4z 3 жыл бұрын
Yeah, I like doggy stuff as well, if you know what I mean)
@pattyyy8071
@pattyyy8071 3 жыл бұрын
@@user-em5ep9zw4z Now I don’t see it the same way lmao
@FrancisCo-xk6rv
@FrancisCo-xk6rv 3 жыл бұрын
Yeah.She's also cute. I want a programmer gf☺
@hozay6552
@hozay6552 3 жыл бұрын
@@FrancisCo-xk6rv oop
@DevBranch
@DevBranch 2 жыл бұрын
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!
@laurenm1696
@laurenm1696 3 жыл бұрын
This video was EXACTLY what I was looking for when trying to practice these concepts. Thank you so much
@andrewyoung222
@andrewyoung222 Жыл бұрын
Clear, concise, pacey video and so helpful on these core concepts of OOP - deserves MANY more views! Thank you!
@oluwalekeoyedeji444
@oluwalekeoyedeji444 2 жыл бұрын
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.
@dearlychrystabellereantill3050
@dearlychrystabellereantill3050 3 жыл бұрын
whoaa. ur so good at explaining everything in just a span of minutes. thank u so much. more videos like this, please
@ScriptedSep
@ScriptedSep Жыл бұрын
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.
@humdrumsnail1036
@humdrumsnail1036 4 ай бұрын
I found Polymorphism a difficult concept to understand but after watching this video, I understood it perfectly well. Thnx for uploading great free content
@rev.dr.metalmatt6827
@rev.dr.metalmatt6827 2 жыл бұрын
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!
@spianny
@spianny Жыл бұрын
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!! 🙏
@chunhimcheung7296
@chunhimcheung7296 2 жыл бұрын
This is a fantastic video with a very simple and straight forward example - keep up the good work!
@kyoli9847
@kyoli9847 2 жыл бұрын
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.
@rachellai1164
@rachellai1164 2 жыл бұрын
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!
@vivekup3424
@vivekup3424 2 жыл бұрын
Great work Kylie. Your Python series is well explained and the examples you use make your videos more interesting.
@jimiwhizz
@jimiwhizz 2 жыл бұрын
Your explanation of each of these topics was extremely clear and easy to understand! Excellent work. Also love the doggos
@ankitabasu81
@ankitabasu81 3 жыл бұрын
Best Example I have ever come across and I wish everybody to use Doggo examples 💖
@jonesbts6393
@jonesbts6393 3 жыл бұрын
I really like how you explained everything... keep up the great work, and keep teaching! I like your format quite a lot. :)
@wendyliu9808
@wendyliu9808 2 жыл бұрын
Thank you so much! Kylie!!! your examples on dog are wonderful!!
@christophejan5587
@christophejan5587 Жыл бұрын
very clear video that allowed an old French man like me to finally understand polymorphism . Merci !
@binarycloud1843
@binarycloud1843 3 ай бұрын
Best example!! Thank you!
@emmanueldel2891
@emmanueldel2891 Ай бұрын
I was confused between the two but now I know the difference, thanks!
@teacherinthailan6441
@teacherinthailan6441 2 жыл бұрын
Awesome lesson! Very clearly explained. Thank you so much!
@GabrielMamuttee
@GabrielMamuttee 3 жыл бұрын
The best explanation I've got on these subjects
@jakesteffan1581
@jakesteffan1581 2 жыл бұрын
THANK YOU. Like the tone and pace of your voice. Easy to digest. Very precise and succinct as well. Subbed. ✌️
@garagemusic9721
@garagemusic9721 2 жыл бұрын
Excellent use of simple examples to explain inheritance and polymorphism :)
@KeithGalli
@KeithGalli 3 жыл бұрын
Nice!
@Me-id3uy
@Me-id3uy 3 жыл бұрын
hey man you also having doupt in opps ............ omg💥💣 i am one of your subscriber and fan of your coding skills 😍
@Twenti2
@Twenti2 2 жыл бұрын
These were awesome watched all within a few days!
@lakshmis8424
@lakshmis8424 11 ай бұрын
Thank you Kylie for such clear explaination using cute examples :)
@jjjjjkkkkk
@jjjjjkkkkk 2 жыл бұрын
Kylie, these videos are so good. They have really helped me a lot.
@nguyentuan6108
@nguyentuan6108 3 жыл бұрын
You deserve a credit for those amazing videos :D Thanks so much
@fawwaz25
@fawwaz25 3 жыл бұрын
Thank you, you are really good at explaining and your examples are super helpful!!
@theemptycup05
@theemptycup05 3 ай бұрын
Thank you so much, you explained this in a super easy to understand way!
@user-oe5qv4gs4t
@user-oe5qv4gs4t Жыл бұрын
You explain wonderfully! Thanks!
@adamsnith-kq2gy
@adamsnith-kq2gy Жыл бұрын
I wish all programming videos on KZbin were this quality
@saudijaz5678
@saudijaz5678 2 жыл бұрын
keep uploading more videos.absolutely amazing.keep up the good work
@Honest_Reply900
@Honest_Reply900 2 жыл бұрын
Amazing , glad that I found it . Good job and thank you
@felipemurta9160
@felipemurta9160 11 ай бұрын
damnn this video was 100x better than I had thought it would be. Deserved a like for sure. Thanks!
@bhaithrinley9602
@bhaithrinley9602 2 жыл бұрын
So much clear explanation... We expect more videos like this...
@1grace
@1grace 3 жыл бұрын
thank you so much! much easier to understand than my prof
@eduardorosales7225
@eduardorosales7225 3 жыл бұрын
Thanks for your excellent explanation!
@tee9166
@tee9166 2 жыл бұрын
thanks queen love the dog examples
@felipe_ai
@felipe_ai 3 жыл бұрын
Seriously, best explanation ever :)
@slyparranini7639
@slyparranini7639 3 жыл бұрын
Thanks very much, explained much better than my uni!
@nishkarshdubb2204
@nishkarshdubb2204 2 жыл бұрын
Thank you for this great video! Helped me a lot.
@tecolote8566
@tecolote8566 3 күн бұрын
SUPER NICE KYLIE!!
@mynamesjeff007
@mynamesjeff007 11 ай бұрын
Thanks for sharing the knowledge. It will now be a stepping stone for me. thanks a lot once again
@user-re1vj1jx4r
@user-re1vj1jx4r Жыл бұрын
best tutorial, loved the doggo examples thnx
@dlwlrmae
@dlwlrmae 3 жыл бұрын
you saved me! thank you so much 💓
@chastippett
@chastippett 2 жыл бұрын
great video Kylie - so helpful
@c.221
@c.221 2 жыл бұрын
Very late comment but this video is absolutely amazing. Concise explanation given in an easy to digest manner. Thank you very much.
@saqibmalik6589
@saqibmalik6589 2 жыл бұрын
will you make more videos? I am eagerly waiting. You are so articulate and very good speaker with clarity in voice.
@dominiczhai
@dominiczhai 3 жыл бұрын
Thanks for the vid Kylie!
@kadimiprasad6517
@kadimiprasad6517 2 жыл бұрын
Thanks Kylie I am really enjoying your pet programming
@shashankkamath2171
@shashankkamath2171 3 жыл бұрын
Wonderful explanation!
@Zetroza
@Zetroza 3 жыл бұрын
print("Thank you. You made it very clear with examples and I now understand the concept.")
@salomepantsulaya5515
@salomepantsulaya5515 2 жыл бұрын
thank you sooo soo much! you explain it so easily and in an interesting way.
@FitnessChaos
@FitnessChaos 2 жыл бұрын
Multiple videos watched on this topic and still couldn't understand because of all the jargon they used. Good video and thanks
@entity5678
@entity5678 Жыл бұрын
Very good explanation..keep it up
@processorbot8761
@processorbot8761 3 жыл бұрын
thank you i really needed a refresh
@Balkac
@Balkac 3 жыл бұрын
Most simple explanation of Polymorfism I've seen so far :) Better than with build in dunder method usual examples.
@KylieYYing
@KylieYYing 3 жыл бұрын
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
@elenaperez6327
@elenaperez6327 2 жыл бұрын
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 🤣😝
@AK-ze1df
@AK-ze1df 2 жыл бұрын
Thankyou so much kylie.. ❤🧚‍♀️for the wonderful explanation
@Klaushennequin
@Klaushennequin 3 жыл бұрын
Amazing. It really helps
@kyawsoe8284
@kyawsoe8284 3 жыл бұрын
Nice Explanation
@Seulementmoietlalune
@Seulementmoietlalune Жыл бұрын
This was so cute. I love it. In my class, we kept using cats but I'm a dog person. lol
@keoz-4125
@keoz-4125 2 жыл бұрын
Thanks for great explanation. U deserve more subs :D
@robinsonzapata1
@robinsonzapata1 3 жыл бұрын
Great tutorial!
@jacksondasilvafilho9319
@jacksondasilvafilho9319 2 жыл бұрын
Wow! Thank you very much! That was a mater class @Kylie Ying
@pythonholic
@pythonholic 2 жыл бұрын
Thank you so much ♥️♥️♥️♥️ you're the best
@klipkon1941
@klipkon1941 2 жыл бұрын
Thank you so much!!
@cheveux9718
@cheveux9718 Жыл бұрын
thankyou so much kylie
@KarlKatten
@KarlKatten 3 жыл бұрын
great video, thank you!
@nrprogramming7593
@nrprogramming7593 3 жыл бұрын
Nice content!
@breamgarces4680
@breamgarces4680 Жыл бұрын
that was clear!
@felipesanchez4097
@felipesanchez4097 2 жыл бұрын
Great video.
@aftereffects00
@aftereffects00 2 жыл бұрын
Thank you for your great tutorial video... Please create more python tutorials for beginner...
@mmmax82
@mmmax82 3 жыл бұрын
this is what i needed :)
@sieroalf7675
@sieroalf7675 2 жыл бұрын
Kylie you're super amazing 💪😊
@chachacharisse
@chachacharisse 2 жыл бұрын
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!
@anandib5401
@anandib5401 3 жыл бұрын
I like her cute little ponytail!!
@markcampos7959
@markcampos7959 3 жыл бұрын
Thank you!
@ricj9594
@ricj9594 3 жыл бұрын
Thank you Mulan!
@buscapee
@buscapee 3 жыл бұрын
Very nice video. 🙏
@modev7189
@modev7189 3 жыл бұрын
Nice❤️
@zibafarhangi6024
@zibafarhangi6024 2 жыл бұрын
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
@hes8518
@hes8518 3 жыл бұрын
queen ty for this
@jpkeys6000
@jpkeys6000 2 жыл бұрын
Subscribed!
@matheusosa
@matheusosa 2 жыл бұрын
How can I like this video more than one time?🧠
@magdaahmed8252
@magdaahmed8252 3 жыл бұрын
Kylie you're amazing❤
@KylieYYing
@KylieYYing 3 жыл бұрын
🥰🥰🥰
@ja1211
@ja1211 2 жыл бұрын
Thank you 😭
@luansouzasilva31
@luansouzasilva31 3 жыл бұрын
Thank you
@xenofeild983
@xenofeild983 2 жыл бұрын
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?
@cuteypatootie
@cuteypatootie 2 жыл бұрын
Subbed great channel =)
@omarkalom1962
@omarkalom1962 3 жыл бұрын
Thanks Kylie. 7:17 The super() in GoldenDoodle refers to which parent class?
@KylieYYing
@KylieYYing 3 жыл бұрын
All of them! Check this out :') class Parent: def __init__(self): print('Init parent') class Child1(Parent): def __init__(self): super().__init__() print('Init child1') class Child2(Parent): def __init__(self): super().__init__() print('Init child2') class GrandChild(Child1, Child2): def __init__(self): super().__init__() print('Init grandchild') GrandChild() This prints: "Init parent Init child2 Init child1 Init grandchild"
@kaushikdr
@kaushikdr 3 жыл бұрын
Thank you so much! I love your clear explanations. I am just wondering - since __init__ is already part of the parent class, we don't really need to create another function to override it, right? Also, what would happen if we have interfering properties between two parent classes (like friendliness for golden retrievers is 7 and friendliness for poodle is 10)?
@KylieYYing
@KylieYYing 3 жыл бұрын
Yeah we don't need init. Also I think this was a bad example. Ideally that would never happen to be honest. Like it should be maybe like an Animal class and a Pet class. If they overlap, there will probably be an error, but I haven't tried it
@edmondchan4438
@edmondchan4438 3 жыл бұрын
Hi Kylie, great videos! I just had a question: in the parent class, this line is def __init__(self, name, age, friendliness) but when we call the parent class in the child class, it's super().__init__(name, age, friendliness). Is there a reason that there's no 'self' in the child class line as there is in the equivalent parent class line? Or is that just the way that it has to be written to work? Thanks!
@buscapee
@buscapee 3 жыл бұрын
You only need the self for initializing the class. And that was already done on the init method. The super is just for calling the previous definitions from the parent class
@edmondchan4438
@edmondchan4438 3 жыл бұрын
@@buscapee ah thanks very much Mané!
@cetilly
@cetilly 2 жыл бұрын
@Kylie Ying Why not make "Dog" an abstract class?
@KeepLearing
@KeepLearing 3 жыл бұрын
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 😅
@dominiczhai
@dominiczhai 3 жыл бұрын
same lol
@dominiczhai
@dominiczhai 3 жыл бұрын
code academy's written explanation was garbage
@thegangmovies4317
@thegangmovies4317 5 ай бұрын
Love you ❤
ПЕЙ МОЛОКО КАК ФОКУСНИК
00:37
Masomka
Рет қаралды 6 МЛН
КАРМАНЧИК 2 СЕЗОН 4 СЕРИЯ
24:05
Inter Production
Рет қаралды 656 М.
Follow @karina-kola please 🙏🥺
00:21
Andrey Grechka
Рет қаралды 13 МЛН
Python OOP Tutorial 4: Inheritance - Creating Subclasses
19:40
Corey Schafer
Рет қаралды 1,3 МЛН
Fundamental Concepts of Object Oriented Programming
9:16
Computer Science
Рет қаралды 827 М.
Java Polymorphism Fully Explained In 7 Minutes
7:16
Coding with John
Рет қаралды 281 М.
5 years of MIT in 20 minutes
21:45
Kylie Ying
Рет қаралды 152 М.
Object Oriented Programming (OOP) in Python
46:37
Traversy Media
Рет қаралды 275 М.
Python Object Oriented Programming (OOP) - For Beginners
53:06
Tech With Tim
Рет қаралды 3,2 МЛН
super/MRO, Python's most misunderstood feature.
21:07
mCoding
Рет қаралды 209 М.
Python Data Classes Are AMAZING! Here's Why
16:11
Tech With Tim
Рет қаралды 64 М.
How to Get a Software Developer Job
16:13
Kylie Ying
Рет қаралды 11 М.
ПЕЙ МОЛОКО КАК ФОКУСНИК
00:37
Masomka
Рет қаралды 6 МЛН