Polymorphism in Python
Polymorphism means objects of different classes can be used through the same interface, each responding to the same method call in its own way. In Python this happens naturally: any object with a matching method name can be used wherever that method is expected, without needing a shared base class or any special declaration — a style often called "duck typing."
Different classes share a method name
Like speak() or area(), defined independently in each class.
Calling code stays agnostic
Code that calls .speak() doesn’t need to know or care exactly which class the object belongs to.
Checked only when actually called
Python looks for the method at call time, not ahead of time — if the object has it, the call works.
One loop can handle many types
As long as each object supports the expected method, a single loop works across all of them.
This is "duck typing"
If it walks like a duck and quacks like a duck, Python treats it as a duck.
class Circle: def area(self): return 3.14 * 5 ** 2 class Square: def area(self): return 4 ** 2 shapes = [Circle(), Square()] for shape in shapes: print(shape.area())Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.