# "Duck typing" = Another way to achieve polymorphism besides Inheritance # Object must have the minimum necessary attributes/methods # "If it looks like a duck and quacks like a duck, it must be a duck." class Animal: alive = True class Dog(Animal): def speak(self): print("WOOF!") class Cat(Animal): def speak(self): print("MEOW!") class Car: alive = True def speak(self): print("HONK!") animals = [Dog(), Cat(), Car()] for animal in animals: animal.speak() print(animal.alive)
# "Duck typing" = Another way to achieve polymorphism besides Inheritance
# Object must have the minimum necessary attributes/methods
# "If it looks like a duck and quacks like a duck, it must be a duck."
class Animal:
alive = True
class Dog(Animal):
def speak(self):
print("WOOF!")
class Cat(Animal):
def speak(self):
print("MEOW!")
class Car:
alive = True
def speak(self):
print("HONK!")
animals = [Dog(), Cat(), Car()]
for animal in animals:
animal.speak()
print(animal.alive)
Thanks dude your 12 hour course encouraged me to learn python!
bro code , can u make video of data structure using python language...?
THIS IS GOAT BRO CODE
You are the best python instructor ive found.
Big fan bro 💪 from india tn , u r rocking bro 🤟🤟🤟😄🔥🔥🔥
From Vietnam with love. I really like your voice. It's very easy to listen to
❤You are the best ❤programming teacher on TH-cam ❤
very good explanation ! Thorougly loved it ! Thank you !
You are the GOAT bro
Whenever I watch your videos I never skip ads
Вижу Бро - ставлю лайк
Dog goes woof, cat goes meow. But, what does the fox say?
bird goes tweet and mouse goes squeak
But then that array under the hood, isn't a list of animals
Wohoo!! We got lightning McQueen cameo in a bro code video before gta 6. Letsss gooo!!!
PRIME