tubeshowcase●1,194,391 videos♡ My collection 0
← Learn to Code

Learn to Code04:20

Learn Python DUCK TYPING in 4 minutes! 🦆

Bro Code ↗

From the creator

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

Published 2024-06-25 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code