Skip to content

Python Polymorphism

New Course Coming Soon:

Get Really Good at Git

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():
        print('Eating dog food')

class Cat:
    def eat():
        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.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Get my Python Handbook
→ Get my Python Handbook

Here is how can I help you: