Python Polymorphism
Polymorphism is a word that came from two Greek words, poly means many and morphos means forms. If something exhibits various forms, it is called as polymorphism.
Let's take a simple example in our daily life. Assume that we have wheat flour. Using this wheat flour, we can make burgers, rotis, or loaves of bread.
It means same wheat flour is taking different edible forms and hence we can say wheat flour is exhibiting polymorphism.
Consider Figure
Where wheat exhibited different edible forms, example of polymorphism.
Polymorphism Implementation
A variable may store different types of data, an object may exhibit different behaviors in different contexts or a method may perform various tasks in Python. This type of behavior is called polymorphism.
So, how can we define polymorphism? If a variable, object or method exhibits different behavior in different contexts, it is called polymorphism. Python has built-in polymorphism.
Polymorphism Examples
- Duck typing philosophy of Python
- Operator overloading
- Method overloading
- Method overriding