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())