🧭Polymorphism
Also known as Method Overriding, Duck Typing
One name that works on many kinds of thing, each doing it its own way.
Think of it like
Think of it like saying speak to a dog and a cat. Each one answers in its own voice.
Example
Lucy's app keeps a list of shapes. One loop calls area() on each, and circles and squares each give the right answer.
Why it matters
It lets you add a new kind of thing without changing the code that uses it.
Definition
Example code
python
>>> len("hi"), len([1, 2, 3])
(2, 3)Common mistake
Key takeaways
- 1One name. Many kinds of thing.
- 2Each its own way. The object decides.
- 3Caller stays simple. No type checks needed.