I agree (or if I am under 13 my parent or guardian agrees on my behalf) to the terms and conditions of use and that: - My test statistics may be published on the site leaderboard against my username - My teacher(s) can review my test scores - I can receive feedback on my tests from my teacher(s)
Polymorphism is the ability of any data to be processed in more than one form. The word itself indicates the meaning as poly means many and morphism means types. 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. Let's take an example:
Example 1: Polymorphism in the addition operator
We know that the + operator is used extensively in Python programs. But, it does not have a single usage. For integer data types, + operator is used to perform arithmetic addition operation.
num1 = 1
num2 = 2
Hence, the above program outputs 3.
Similarly, for string data types, + operator is used to perform concatenation.
As a result, the above program outputs Python Programming. Here, we can see that a single operator + has been used to carry out different operations for distinct data types. This is one of the most simple occurrences of polymorphism in Python.