Explain the Python Polymorphism with example.
Explain the Python Polymorphism with example.
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM
06-Oct-2025In Python, polymorphism is mainly seen with:
Example 1: Built-in Polymorphism
Some Python functions work differently depending on the data type.
Same function name (
len), different behavior depending on the data type.Example 2: Polymorphism with Class Methods (Method Overriding)
When a child class overrides a method from its parent, both have the same name but different implementations.
Output:
Here, the same method name
speak()behaves differently depending on the object’s class — that’s polymorphism.Example 3: Polymorphism with a Common Interface
Multiple classes can implement the same method name, even if they’re unrelated.
Output:
Python doesn’t care what the object is, as long as it has a
make_sound()method — this is called duck typing:Example 4: Polymorphism with Inheritance and
super()Output:
Both shapes use the same
area()method — but behave differently.Summary