Posts

Showing posts from April, 2019

Polymorphism in Python

Image
   Concept Polymorphism  is the ability of an object to take on many forms. The most common use of  polymorphism  in OOP occurs when a parent class reference is used to refer to a child class object. Polymorphism in python  defines methods in the child class that have the same name as the methods in the parent class. In inheritance, the child class inherits the methods from the parent class. Also, it is possible to modify a method in a child class that it has inherited from the parent class Code Example The word polymorphism means having many forms. In programming, polymorphism means the same function name (but different signatures) being uses for different types First Let me show you Builtin Example: len('Hello world') len([1,2,3,4,5]) len((1,2,3,4,5)) From the above example, you can see len() function is taking different from of input.  def add(x=1, y=2, z=3):        res = x + y + z        return res print(add()) ---> 6 print(add(5,2))  ----> 10 print(add(1,1,1))  -