Sitemap
Parthpritam

Parthpritam

POLYMORPHISM IN PYTHON

1 min readMay 19, 2022

--

Press enter or click to view image in full size

What is Polymorphism?

The literal meaning of polymorphism is the condition of occurrence in different forms.

Get Parthpritam’s stories in your inbox

Join Medium for free to get updates from this writer.

Polymorphism is a very important concept in programming. It refers to the use of a single type entity (method, operator or object) to represent different types in different scenarios.

Polymorphism In Class methods

Polymorphism with class methods is useful when we group different objects having the same method. we can add them to a list or a tuple, and we don’t need to check the object type before calling their methods. Instead, Python will check object type at runtime and call the correct method. Thus, we can call the methods without being concerned about which class type each object is. We assume that these methods exist in each class.

Polymorphism in Built-in function len()

The built-in function len() calculates the length of an object depending upon its type. If an object is a string, it returns the count of characters, and If an object is a list, it returns the count of items in a list.

The len() method treats an object as per its class type.

--

--