AI Workshop: learn to build apps with AI →
Functions and OOP: Polymorphism

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Polymorphism generalizes a functionality so it can work on different types. It’s an important concept in object-oriented programming.

We can define the same method on different classes:

class Dog:
    def eat(self):
        print('Eating dog food')

class Cat:
    def eat(self):
        print('Eating cat food')

Then we can generate objects and we can call the eat() method regardless of the class the object belongs to, and we’ll get different results:

animal1 = Dog()
animal2 = Cat()

animal1.eat()
animal2.eat()

We built a generalized interface and we now do not need to know that an animal is a Cat or a Dog.

Lessons in this unit:

0: Introduction
1: Functions
2: Lambda functions
3: Nested functions
4: Recursion
5: Closures
6: Objects
7: Classes
8: ▶︎ Polymorphism
9: Operator overloading