Polymorphism

Lesson 15 of 20

One loop, many shapes: duck typing and method overriding let different objects all answer the same call.

The big picture

Same call, different answers

Polymorphism means many forms: one method name works across classes, and Python simply asks the object to do its thing.

Same Name, Many Shapes

Different classes can define the same method — speak, sound, draw — each in its own way.

Duck Typing

Python calls the method if it exists; the class name is never inspected first.

Loops Stay Simple

Your loop code never changes when you add a new type to the list.

Overriding

Subclasses can replace inherited methods — the child version wins for its objects.