Posts

Showing posts with the label Polymorphism

Python Object Oriented Programming - Polymorphism

Image
Polymorphism means many forms. It is one of the most crucial concepts in programming. It refers to the use of a single entity like method or operator to represent different types different use cases. Function polymorphism Python has several functions that accept different types of arguments. One such function is len() which accepts different types of data. Here is an example of polymorphism using len(): str = 'Knowledge Factory'       #String my_list = [ 1 , 33.3 , 'Carl' ]     #List elem = ( 4 , 'python' , 2 + 3 j )       #Tuple a = { 5 , 2 , 3 , 1 , 4 }                 #Set d = { 123 : 'python' , '234' : 'go' }   #Dictionary print(len(str))     #Length of String print(len(my_list)) #Length of List print(len(elem))     #Length of Tuple print(len(a))       #Length of Set print(len(d))       #Length of Dictionary Console output: 17 3 3 5 2 Here, you can see that the len() function can be used with different types of data, such as strings,