4/6 OOP & Classes in Python: Class Inheritance, Subclasses & Super Function

Поделиться
HTML-код
  • Опубликовано: 27 янв 2025

Комментарии • 19

  • @FabioMusanni
    @FabioMusanni  Год назад

    ⬇️ *LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW)* 😉💪 ⬇️
    ☕ *Buy me a coffee:* www.buymeacoffee.com/fabiomusanni
    ❤️ *Support me monthly:* www.patreon.com/FabioMusanni
    😍 *One-off donation:* www.paypal.me/FabioMusanni/
    *SKILLSHARE*
    _(Python, Web Dev, UI/UX Design, Music, Art, Animation and a lot more)_
    🔗 skillshare.eqcm.net/5gxzD2 (Affiliate)
    *DATACAMP*
    _(Python, ChatGPT, SQL, Power BI, and a lot more)_
    🔗 datacamp.pxf.io/vN1bDj (Affiliate)
    *COURSERA PYTHON*
    _(For beginners, Data Science, Data Analysis, AI, Cybersecurity and a lot more):_
    🔗 imp.i384100.net/k0Nk60 (Affiliate)
    *COURSERA WEB DEVELOPMENT*
    _(Full Stack, Front-End, Back-End, Web Design and a lot more):_
    🔗 imp.i384100.net/EKWxBW (Affiliate)
    Thank you for the support!❤
    🎥OOP & Classes Playlist: ruclips.net/p/PLs8qUrmRvaR2LSaVLSvAGykNexBLrRqNt
    🎥All my videos about Python: ruclips.net/p/PLs8qUrmRvaR0IT4IwJl-LSweAdACW-yLK

  • @21pradaofficial4
    @21pradaofficial4 Год назад +5

    thank you for the video, super helpful and straight to the point

    • @FabioMusanni
      @FabioMusanni  Год назад

      Thank you so much for taking the time to leave a comment! I'm glad it was helpful 🤩💪

  • @lloyd_talks
    @lloyd_talks Год назад +1

    You are the BEST in explaining OOP!! Great playlist 👍🏽

    • @FabioMusanni
      @FabioMusanni  Год назад +1

      Thank you for the comment! I put a lot of effort into making this playlist, so I really appreciate it! 🥹💪
      If you want to support the channel just a little bit you can buy me a coffee or get the source code of my videos here: www.buymeacoffee.com/fabiomusanni
      Thank you again! 🤗

  • @fa7234
    @fa7234 Год назад +1

    Great job Fabio 👍🏼

  • @leventefaludi-orszagh211
    @leventefaludi-orszagh211 2 месяца назад

    Thank You!

    • @FabioMusanni
      @FabioMusanni  2 месяца назад

      Glad you liked the video! 💪😉

  • @amarmusovic7748
    @amarmusovic7748 7 месяцев назад

    Thanks for the video!

  • @13bimbou
    @13bimbou 8 месяцев назад +1

    Hi. Thank you for that nice video.
    At 5:09 i dont get how and why printing "player1.introduction()" works as we dont really call the method. We are "printing" a print and a return statement i don't get how that can print our 2 lines.
    Thanks for clarifications :-)

    • @FabioMusanni
      @FabioMusanni  8 месяцев назад

      Thank you for the comment! 😊
      Notice that we are also printing on line 28, so when you call introduction, you print the first string, then you call the parent introduction, which returns the second string, and then you return that second string and you print it (line 28).
      Maybe if we break that down a little more it's easier to understand:
      def introduction(self):
      print('Player introduction')
      second_string = super().introduction()
      return second_string
      So on line 28 it's sort of like:
      print(second_string)
      Because that's the value returned by the introduction method.
      Hopefully that's clearer now 😊💪

  • @yeoshuabenzaken7736
    @yeoshuabenzaken7736 Год назад

    why in the class player do you need __init__(self, name, age, city, level)shouldn't just be __init__(self,level) because you are bringing the parent class person with "super.(__init__(name,age,city)"?

    • @FabioMusanni
      @FabioMusanni  Год назад +1

      Hello,
      in this case, if when creating an instance of the class Player, you want to be able to pass name, age, city and level (4 arguments), then you need to have all of them as parameters of the init method of the Player class, If you were to just write (self, level), then when creating the instance, you'd only be able to enter one argument:
      Player(45)
      And of course you wouldn't have the name, age and city to then use with super().
      It doesn't matter if you are using super() inside the class, Python just sees that when you create an instance of Player, you can enter just 1 argument (level) and nothing else, if you try to enter also name, age and city, you would get an error because you are passing more arguments than expected.
      That's why you need to have all of them there, even if you are using super().
      If this helped and my videos are helpful for you, consider supporting the channel with a little donation, I'd really appreciate it: www.buymeacoffee.com/fabiomusanni

    • @yeoshuabenzaken7736
      @yeoshuabenzaken7736 Год назад

      I'll subscribe to your channel@@FabioMusanni

  • @yeoshuabenzaken7736
    @yeoshuabenzaken7736 Год назад

    I can do "Person.__init__(name, age, city) instead of "super().__init__(name, age, city) correct?

    • @FabioMusanni
      @FabioMusanni  Год назад +1

      That would work but you are hard-coding it. You wouldn't have problems if you use that in small programs, but there could be instances where it might cause problems, especially if your code needs to be used by someone else.
      If I were to choose between using super() or hard-coding the value of the parent, I'd always use super().

    • @yeoshuabenzaken7736
      @yeoshuabenzaken7736 Год назад

      Thanks

  • @alexikamran7039
    @alexikamran7039 Год назад +3

    you jump very fast not good for new guys. Bad!