Python INHERITANCE in 6 minutes! 👨‍👦‍👦

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • Inheritance = Inherit attributes and methods from another class
    Helps with code reusability and extensibility
    class Child(Parent)
    class Animal:
    def __init__(self, name):
    self.name = name
    self.is_alive = True
    def eat(self):
    print(f"{self.name} is eating")
    def sleep(self):
    print(f"{self.name} is asleep")
    class Dog(Animal):
    def speak(self):
    print("WOOF!")
    class Cat(Animal):
    def speak(self):
    print("MEOW!")
    class Mouse(Animal):
    def speak(self):
    print("SQUEEK!")
    dog = Dog("Scooby")
    cat = Cat("Garfield")
    mouse = Mouse("Mickey")

ความคิดเห็น • 13

  • @BroCodez
    @BroCodez  4 หลายเดือนก่อน +3

    # Inheritance = Allows a class to inherit attributes and methods from another class
    # Helps with code reusability and extensibility
    # class Child(Parent)
    class Animal:
    def __init__(self, name):
    self.name = name
    self.is_alive = True
    def eat(self):
    print(f"{self.name} is eating")
    def sleep(self):
    print(f"{self.name} is asleep")
    class Dog(Animal):
    def speak(self):
    print("WOOF!")
    class Cat(Animal):
    def speak(self):
    print("MEOW!")
    class Mouse(Animal):
    def speak(self):
    print("SQUEEK!")
    dog = Dog("Scooby")
    cat = Cat("Garfield")
    mouse = Mouse("Mickey")

  • @colacoca7639
    @colacoca7639 4 หลายเดือนก่อน +1

    You are my idol, how do you learn so fast, im inspired

  • @VishalK-fe9gq
    @VishalK-fe9gq หลายเดือนก่อน +1

    class Father:
    height = 182
    color = "pink"💀

  • @ZelaMawla
    @ZelaMawla 3 หลายเดือนก่อน +1

    I want to ask, so whats the point for using super() in child class?

    • @burt591
      @burt591 22 วันที่ผ่านมา

      I'm wondering the same

    • @burt591
      @burt591 22 วันที่ผ่านมา

      From what I could gather, the super and __init__ in the child class is needed if any attribute is added to the child class.
      Since in this case no new attribute was added, it wasn't necessary.
      If you don't override the __init__ method in the subclass Python implicitly uses the __init__ from the parent class.

  • @Johnvids-g3o
    @Johnvids-g3o 5 วันที่ผ่านมา

    Who likes dogs/cats?🐶🐱
    (I'm a like beggar beacuse many people are like beggars)
    👇

  • @burt591
    @burt591 22 วันที่ผ่านมา +1

    Don't you need to use super?
    What the difference between doing inheritance like this and doing it with super?

  • @to4698
    @to4698 4 หลายเดือนก่อน +2

    Excellent explanation. Thank you for sharing your knowledge with novice programmers.

  • @sunkorg
    @sunkorg 4 หลายเดือนก่อน +1

    Cool! Do you have any plans to provide a video where you're comparing inheritance against multiple different popular languages for their differences? Example: Python inheritance vs. JavaScript vs. C# vs. Java, etc. 😊

  • @badger-mr1fi
    @badger-mr1fi 4 หลายเดือนก่อน

    Thanks, just what I needed :)

  • @yezanelcuma7802
    @yezanelcuma7802 4 หลายเดือนก่อน

    i love ur vids brocode

  • @ProfShibe
    @ProfShibe 4 หลายเดือนก่อน

    the goat