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

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • 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

Komentáře • 183

  • @KylieYYing
    @KylieYYing  Před 3 lety +24

    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 Před 3 lety

      Thanks kylie!’ So whats next?

    • @KylieYYing
      @KylieYYing  Před 3 lety +9

      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 Před 3 lety

      Kylie Ying sounds great! Would love to hear more about your research

    • @simbian4345
      @simbian4345 Před 3 lety

      I like it when you say "Arf arf!"

    • @vickkyphogat
      @vickkyphogat Před 2 lety +1

      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 Před 3 lety +52

    Who in the world would dislike this video? She is amazing and used doggies for the example.

    • @kaushikdr
      @kaushikdr Před 3 lety +2

      People who dislike this video are cute dog haters :)

    • @user-em5ep9zw4z
      @user-em5ep9zw4z Před 3 lety +2

      Yeah, I like doggy stuff as well, if you know what I mean)

    • @pattyyy8071
      @pattyyy8071 Před 3 lety

      @@user-em5ep9zw4z Now I don’t see it the same way lmao

    • @FrancisCo-xk6rv
      @FrancisCo-xk6rv Před 3 lety +2

      Yeah.She's also cute. I want a programmer gf☺

    • @hozay6552
      @hozay6552 Před 3 lety +1

      @@FrancisCo-xk6rv oop

  • @DevBranch
    @DevBranch Před 3 lety +30

    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!

  • @WaldoTheWombat
    @WaldoTheWombat Před 2 měsíci +1

    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

  • @humdrumsnail1036
    @humdrumsnail1036 Před 8 měsíci +1

    I found Polymorphism a difficult concept to understand but after watching this video, I understood it perfectly well. Thnx for uploading great free content

  • @ankitabasu81
    @ankitabasu81 Před 3 lety +5

    Best Example I have ever come across and I wish everybody to use Doggo examples 💖

  • @laurenm1696
    @laurenm1696 Před 3 lety +13

    This video was EXACTLY what I was looking for when trying to practice these concepts. Thank you so much

  • @andrewyoung222
    @andrewyoung222 Před rokem +3

    Clear, concise, pacey video and so helpful on these core concepts of OOP - deserves MANY more views! Thank you!

  • @ScriptedSep
    @ScriptedSep Před rokem +1

    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.

  • @christophejan5587
    @christophejan5587 Před 2 lety

    very clear video that allowed an old French man like me to finally understand polymorphism . Merci !

  • @spianny
    @spianny Před rokem +3

    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!! 🙏

  • @dearlychrystabellereantill3050

    whoaa. ur so good at explaining everything in just a span of minutes. thank u so much. more videos like this, please

  • @KeithGalli
    @KeithGalli Před 3 lety +8

    Nice!

    • @Me-id3uy
      @Me-id3uy Před 3 lety

      hey man
      you also having doupt in opps ............ omg💥💣
      i am one of your subscriber and fan of your coding skills 😍

  • @emmanueldel2891
    @emmanueldel2891 Před 5 měsíci

    I was confused between the two but now I know the difference, thanks!

  • @ggg9gg
    @ggg9gg Před 2 lety

    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.

  • @oluwalekeoyedeji444
    @oluwalekeoyedeji444 Před 3 lety

    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.

  • @felipemurta9160
    @felipemurta9160 Před rokem

    damnn this video was 100x better than I had thought it would be. Deserved a like for sure. Thanks!

  • @adamsnith-kq2gy
    @adamsnith-kq2gy Před rokem

    I wish all programming videos on CZcams were this quality

  • @rachellai1164
    @rachellai1164 Před 3 lety +1

    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!

  • @theemptycup05
    @theemptycup05 Před 6 měsíci

    Thank you so much, you explained this in a super easy to understand way!

  • @Jeefffツ
    @Jeefffツ Před rokem

    Thanks for sharing the knowledge. It will now be a stepping stone for me. thanks a lot once again

  • @tecolote8566
    @tecolote8566 Před 3 měsíci +1

    SUPER NICE KYLIE!!

  • @kadimiprasad6517
    @kadimiprasad6517 Před 2 lety

    Thanks Kylie I am really enjoying your pet programming

  • @chunhimcheung7296
    @chunhimcheung7296 Před 2 lety +1

    This is a fantastic video with a very simple and straight forward example - keep up the good work!

  • @lakshmis8424
    @lakshmis8424 Před rokem +1

    Thank you Kylie for such clear explaination using cute examples :)

  • @vivekup3424
    @vivekup3424 Před 2 lety +1

    Great work Kylie. Your Python series is well explained and the examples you use make your videos more interesting.

  • @Zetroza
    @Zetroza Před 3 lety +1

    print("Thank you. You made it very clear with examples and I now understand the concept.")

  • @GabrielMamuttee
    @GabrielMamuttee Před 3 lety +1

    The best explanation I've got on these subjects

  • @user-re1vj1jx4r
    @user-re1vj1jx4r Před rokem

    best tutorial, loved the doggo examples thnx

  • @FitnessChaos
    @FitnessChaos Před 2 lety

    Multiple videos watched on this topic and still couldn't understand because of all the jargon they used. Good video and thanks

  • @Seulementmoietlalune
    @Seulementmoietlalune Před 2 lety

    This was so cute. I love it. In my class, we kept using cats but I'm a dog person. lol

  • @rev.dr.metalmatt6827
    @rev.dr.metalmatt6827 Před 3 lety +1

    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!

  • @jakesteffan1581
    @jakesteffan1581 Před 2 lety

    THANK YOU. Like the tone and pace of your voice. Easy to digest. Very precise and succinct as well. Subbed. ✌️

  • @wendyliu9808
    @wendyliu9808 Před 2 lety

    Thank you so much! Kylie!!! your examples on dog are wonderful!!

  • @jimiwhizz
    @jimiwhizz Před 3 lety

    Your explanation of each of these topics was extremely clear and easy to understand! Excellent work. Also love the doggos

  • @chachacharisse
    @chachacharisse Před 3 lety

    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!

  • @tee9166
    @tee9166 Před 2 lety

    thanks queen love the dog examples

  • @anandib5401
    @anandib5401 Před 3 lety

    I like her cute little ponytail!!

  • @matheusosa
    @matheusosa Před 2 lety

    How can I like this video more than one time?🧠

  • @jonesbts6393
    @jonesbts6393 Před 3 lety +1

    I really like how you explained everything... keep up the great work, and keep teaching! I like your format quite a lot. :)

  • @Akshayaak2
    @Akshayaak2 Před 2 lety

    Thankyou so much kylie.. ❤🧚‍♀️for the wonderful explanation

  • @Twenti2
    @Twenti2 Před 3 lety

    These were awesome watched all within a few days!

  • @garagemusic9721
    @garagemusic9721 Před 3 lety

    Excellent use of simple examples to explain inheritance and polymorphism :)

  • @slyparranini7639
    @slyparranini7639 Před 3 lety

    Thanks very much, explained much better than my uni!

  • @binarycloud1843
    @binarycloud1843 Před 6 měsíci

    Best example!! Thank you!

  • @user-oe5qv4gs4t
    @user-oe5qv4gs4t Před 2 lety

    You explain wonderfully! Thanks!

  • @bhaithrinley9602
    @bhaithrinley9602 Před 2 lety

    So much clear explanation...
    We expect more videos like this...

  • @elenaperez6327
    @elenaperez6327 Před 3 lety +1

    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 🤣😝

  • @Balkac
    @Balkac Před 3 lety

    Most simple explanation of Polymorfism I've seen so far :) Better than with build in dunder method usual examples.

    • @KylieYYing
      @KylieYYing  Před 3 lety

      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

  • @entity5678
    @entity5678 Před rokem

    Very good explanation..keep it up

  • @xzex2609
    @xzex2609 Před rokem

    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

  • @saudijaz5678
    @saudijaz5678 Před 2 lety

    keep uploading more videos.absolutely amazing.keep up the good work

  • @godswillspio7430
    @godswillspio7430 Před měsícem

    Thanks love this was really helpful

  • @aftereffects00
    @aftereffects00 Před 2 lety +1

    Thank you for your great tutorial video... Please create more python tutorials for beginner...

  • @samanthapennington4232
    @samanthapennington4232 Před 2 měsíci

    This video was execellent

  • @teacherinthailan6441
    @teacherinthailan6441 Před 3 lety

    Awesome lesson! Very clearly explained. Thank you so much!

  • @jjjjjkkkkk
    @jjjjjkkkkk Před 2 lety

    Kylie, these videos are so good. They have really helped me a lot.

  • @Honest_Reply900
    @Honest_Reply900 Před 2 lety

    Amazing , glad that I found it . Good job and thank you

  • @nguyentuan6108
    @nguyentuan6108 Před 3 lety

    You deserve a credit for those amazing videos :D Thanks so much

  • @KeepLearing
    @KeepLearing Před 3 lety +1

    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 😅

  • @sieroalf7675
    @sieroalf7675 Před 2 lety

    Kylie you're super amazing 💪😊

  • @1grace
    @1grace Před 3 lety

    thank you so much! much easier to understand than my prof

  • @c.221
    @c.221 Před 2 lety

    Very late comment but this video is absolutely amazing. Concise explanation given in an easy to digest manner. Thank you very much.

  • @saqibmalik6589
    @saqibmalik6589 Před 2 lety

    will you make more videos? I am eagerly waiting. You are so articulate and very good speaker with clarity in voice.

  • @cheveux9718
    @cheveux9718 Před rokem

    thankyou so much kylie

  • @nishkarshdubb2204
    @nishkarshdubb2204 Před 3 lety

    Thank you for this great video! Helped me a lot.

  • @jacksondasilvafilho9319

    Wow! Thank you very much! That was a mater class @Kylie Ying

  • @chastippett
    @chastippett Před 3 lety

    great video Kylie - so helpful

  • @fawwaz25
    @fawwaz25 Před 3 lety

    Thank you, you are really good at explaining and your examples are super helpful!!

  • @ricj9594
    @ricj9594 Před 3 lety

    Thank you Mulan!

  • @felipe_ai
    @felipe_ai Před 3 lety

    Seriously, best explanation ever :)

  • @thegangmovies4317
    @thegangmovies4317 Před 9 měsíci +1

    Love you ❤

  • @eduardorosales7225
    @eduardorosales7225 Před 3 lety

    Thanks for your excellent explanation!

  • @keoz-4125
    @keoz-4125 Před 2 lety

    Thanks for great explanation. U deserve more subs :D

  • @shashankkamath2171
    @shashankkamath2171 Před 3 lety

    Wonderful explanation!

  • @salomepantsulaya5515
    @salomepantsulaya5515 Před 2 lety

    thank you sooo soo much! you explain it so easily and in an interesting way.

  • @md.mahbubanamtanim9081
    @md.mahbubanamtanim9081 Před 9 měsíci

    How cool is that.!!?
    NO, mam.... I would rather say, "How cool your explanation is!!".

  • @pythonholic
    @pythonholic Před 2 lety

    Thank you so much ♥️♥️♥️♥️ you're the best

  • @saeidgholami2795
    @saeidgholami2795 Před 3 lety

    10 out of 10

  • @jitendersingh-ju8bz
    @jitendersingh-ju8bz Před rokem

    you are gret, Appreciate that but
    please discuss the difference b/n function and Class in brief.....

  • @klipkon1941
    @klipkon1941 Před 2 lety

    Thank you so much!!

  • @AdilAli-lo7dq
    @AdilAli-lo7dq Před rokem

    Came for the looks stayed for the information

  • @felipesanchez4097
    @felipesanchez4097 Před 2 lety

    Great video.

  • @dominiczhai
    @dominiczhai Před 3 lety

    Thanks for the vid Kylie!

  • @breamgarces4680
    @breamgarces4680 Před 2 lety

    that was clear!

  • @edmondchan4438
    @edmondchan4438 Před 3 lety +2

    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 Před 3 lety +1

      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 Před 3 lety

      @@buscapee ah thanks very much Mané!

  • @Klaushennequin
    @Klaushennequin Před 3 lety

    Amazing. It really helps

  • @zibafarhangi6024
    @zibafarhangi6024 Před 3 lety

    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

  • @markcampos7959
    @markcampos7959 Před 3 lety

    Thank you!

  • @xx482
    @xx482 Před 2 lety

    Woof woof i like this tutorial ........................

  • @dlwlrmae
    @dlwlrmae Před 3 lety

    you saved me! thank you so much 💓

  • @KarlKatten
    @KarlKatten Před 3 lety

    great video, thank you!

  • @luansouzasilva31
    @luansouzasilva31 Před 3 lety

    Thank you

  • @xenofeild983
    @xenofeild983 Před 2 lety

    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?

  • @sudhanvagr
    @sudhanvagr Před 3 lety +1

    Is that compiler VS Code or Pycharm?

  • @rznirvana
    @rznirvana Před rokem

    can you teach a master class to all programming profs and tutors out there how to teach clearly and intuitively as you do?

  • @processorbot8761
    @processorbot8761 Před 3 lety

    thank you i really needed a refresh

  • @robinsonzapata1
    @robinsonzapata1 Před 3 lety

    Great tutorial!

  • @myokaung7060
    @myokaung7060 Před 3 lety

    How can we build multiple inheritance if Poodle and Golden Retriver have different attributes?

  • @nrprogramming7593
    @nrprogramming7593 Před 3 lety +1

    Nice content!