Duck Typing In Python In 4 Minutes!🐍

Поділитися
Вставка
  • Опубліковано 21 січ 2025

КОМЕНТАРІ • 2

  • @YousefCompSci
    @YousefCompSci  2 місяці тому +1

    # duck typing = concept where the class of an object is less important than the methods/attributes
    # class type is not checked if minimum methods/attributes are present
    # “If it walks like a duck, and it quacks like a duck, then it must be a duck.”
    class Duck:
    def walk(self):
    print("This duck is walking")
    def talk(self):
    print("This duck is qwuacking")
    class Chicken:
    def walk(self):
    print("This chicken is walking")
    def talk(self):
    print("This chicken is clucking")
    class Person():
    def catch(self, duck):
    duck.walk()
    duck.talk()
    print("You caught the animal")
    duck = Duck()
    chicken = Chicken()
    person = Person()
    person.catch(duck)

  • @Monsta1291
    @Monsta1291 2 місяці тому

    🎉🎉🎉