Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Python

Polymorphism in Python

Call the same method name on different objects and get type-specific behavior.

Polymorphism in Python — a practical guide to Python polymorphism with clear examples you can reuse in real projects.

Python Tutorial Series (48/95). Prefer one article? Read the complete Python tutorial.

Short description

Polymorphism lets you write code that works with many types sharing an interface.

Polymorphism demo

class Cat:
    def speak(self):
        return 'Meow'

class Dog:
    def speak(self):
        return 'Woof'

for animal in (Cat(), Dog()):
    print(animal.speak())

Leave a reply

Your email address will not be published. Required fields are marked *