Polymorphism in Python

Gauri wankhade
2 min readSep 19, 2020

Polymorphism is an ability to take many forms.

We have learned about polymorphism earlier, not just learned but also we see polymorphism everywhere. What does that mean?

Well, you perform polymorphism everytime you write a story, go to gym, attend a lecture or cook your favourite meal.How your daily life explained polymorphism , the answer is when you write a story you are writer, when you attend a lecture you are learner that’s different form of yours. Here you act as a subject in different situations.

Polymorphism in Python

Python has some inbuilt polymorphic functions.Above example stated len() function can be used to find out length of list of integers as well as length of string. Here len() function is compatible to work with multiple data types.

Polymorphism in Class methods

Output

Here, we have created two classes Maneger and Receptionist . They have same methods intro() and salary().

However, notice that we have not linked the classes together in any way. Even then, we can pack these two different objects into a tuple and iterate through it using a common info variable. It is possible due to polymorphism.

I have mentioned only two types of polymorphism here but there is more say polymorphism with functions and objects ,polymorphism with inheritance.We may discuss it sometime soon.

Thank you for reading this article, and I hope you enjoyed it.

--

--