UNIT 03 · TOPIC 15
Polymorphism
Polymorphism lets different object types respond to the same operation in their own way.
The idea
Polymorphism, simply explained
Polymorphism lets different object types respond to the same operation in their own way.
01
See the big picture
How the idea flows
Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.
02
Everyday connection
Real-life example
↗
Different payment methods can all expose pay(amount), while each handles payment differently.
03
Learn by doing
Python code example
PYTHONExample
class Card:
def pay(self): return 'card'
class Cash:
def pay(self): return 'cash'
print([method.pay() for method in (Card(), Cash())])Expected result
['card', 'cash']Try it: Change one value in the code, predict what will happen, then run it and compare your answer.
04
Keep this in mind
Key takeaways
- Polymorphism lets different object types respond to the same operation in their own way.
- Think of a real problem where polymorphism could save time or organize information.
- Test small changes and read the result carefully before moving to a bigger program.
Quick self-check
Can you explain it in your own words?
What is the main idea of Polymorphism?
Polymorphism lets different object types respond to the same operation in their own way.
Where could you see this idea in everyday life?
Different payment methods can all expose pay(amount), while each handles payment differently.
