Python INHERITANCE in 6 minutes! 👨‍👦‍👦

preview_player
Показать описание
# Inheritance = Inherit attributes and methods from another class
# Helps with code reusability and extensibility
# class Child(Parent)

class Animal:
def __init__(self, name):

def eat(self):

def sleep(self):

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")
Рекомендации по теме
Комментарии
Автор

# 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")

BroCodez
Автор

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

to
Автор

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. 😊

sunkorg
Автор

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

colacoca
Автор

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

VishalK-fegq
Автор

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

ZelaMawla