Polymorph Is M
Polymorph Is M
A Comprehensive
Overview
PS by Pundreekaksha Sharma
Introduction to Polymorphism
Definition
Polymorphism is the ability of an object to take on many forms. It allows us to write code that can
work with objects of different classes, but still behave in a consistent way.
Importance
Types
There are three types of polymorphism in Python: method overloading, method overriding, and
operator overloading.
Method Overloading
1 Definition
Method overloading is the process of defining multiple methods with the same name but with
different parameters.
2 Example 1
def add(a, b):
return a + b
def add(a, b, c):
return a + b + c
3 Example 2
class Rectangle:
def area(self, a=None, b=None):
if a and b:
return a * b
elif a:
return a * a
else:
return "Need to provide at least one argument."
Method Overriding