The word “poly” means many and “morphs” means forms, so it means many forms.
Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations.
Polymorphism gives you the ability to represent objects of different types using a single interface. A real-life example is “You”.
You act like a student when you are at college, you act like a son/daughter when you're at home, and you act like a friend when you're surrounded by your friends.
Polymorphism is an essential part of object-oriented programming (OOP) concepts in Python, as it allows for redefining functions for different objects without losing their original meaning or purpose.
Duck Typing :- This type of polymorphism involves checking only that an object has a certain set of methods or properties, rather than checking its type. If a function expects an object with certain attributes, such as a particular method or property, the code will execute without raising an error even if the object is not the correct type. This makes duck typing very useful in maintaining flexibility while writing code in Python.
Method Overloading :- In method overloading, you can define two or more functions with the same name but different arguments. By providing different arguments for each function call, Python will determine which version of the function to call based on how you pass those arguments in each call. This can be used to provide alternative implementations for similar tasks using the same function name but with different numbers of arguments.
Operator Overloading :-
Method Overriding :- This type of polymorphism occurs when you define two functions with the same name and arguments in a child class that overrides an existing parent class method. This enables you to extend an existing implementation without modifying it directly. To achieve this concept in Python, use inheritance when creating classes so that child classes can override existing methods from their parent classes.