<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Prasanna Vadlamudi on Medium]]></title>
        <description><![CDATA[Stories by Prasanna Vadlamudi on Medium]]></description>
        <link>https://medium.com/@prasannavadlamudi162611?source=rss-ae0fb8ece824------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SgZxVv3rIa14DGux</url>
            <title>Stories by Prasanna Vadlamudi on Medium</title>
            <link>https://medium.com/@prasannavadlamudi162611?source=rss-ae0fb8ece824------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:23:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prasannavadlamudi162611/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Polymorphism in python]]></title>
            <link>https://medium.com/@prasannavadlamudi162611/polymorphism-in-python-e8ca4cbca8b1?source=rss-ae0fb8ece824------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8ca4cbca8b1</guid>
            <dc:creator><![CDATA[Prasanna Vadlamudi]]></dc:creator>
            <pubDate>Thu, 18 Jan 2024 07:50:47 GMT</pubDate>
            <atom:updated>2024-01-18T07:58:24.558Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog let us try to understand what is polymorphism and how to use polymorphism with class methods, inheritance, functions and objects</p><p><strong>Polymorphism</strong>: The word polymorphism means having many forms. In programming, polymorphism means the same function name (but different signatures) being used for different types. The key difference is the data types and number of arguments used in function.</p><p><strong>Example of inbuilt polymorphic functions:</strong></p><pre># len() being used for a string<br>print(len(&quot;geeks&quot;))<br> <br># len() being used for a list<br>print(len([10, 20, 30]))<br><br>Output:<br>5<br>3</pre><p># A simple Python function to demonstrate <br># Polymorphism</p><pre>def add(x, y, z = 0): <br>    return x + y+z<br> <br># Driver code <br>print(add(2, 3))<br>print(add(2, 3, 4))<br><br>Output:<br>5<br>9</pre><p><strong>Polymorphism with class methods:</strong></p><p>The below code shows how Python can use two different class types, in the same way. We create a for loop that iterates through a tuple of objects. Then call the methods without being concerned about which class type each object is. We assume that these methods actually exist in each class.</p><pre>class India():<br> def capital(self):<br>  print(&quot;New Delhi is the capital of India.&quot;)<br><br> def language(self):<br>  print(&quot;Hindi is the most widely spoken language of India.&quot;)<br><br> def type(self):<br>  print(&quot;India is a developing country.&quot;)<br><br>class USA():<br> def capital(self):<br>  print(&quot;Washington, D.C. is the capital of USA.&quot;)<br><br> def language(self):<br>  print(&quot;English is the primary language of USA.&quot;)<br><br> def type(self):<br>  print(&quot;USA is a developed country.&quot;)<br><br>obj_ind = India()<br>obj_usa = USA()<br>for country in (obj_ind, obj_usa):<br> country.capital()<br> country.language()<br> country.type()<br><br>Output:<br>New Delhi is the capital of India.<br>Hindi is the most widely spoken language of India.<br>India is a developing country.<br>Washington, D.C. is the capital of USA.<br>English is the primary language of USA.<br>USA is a developed country.</pre><p><strong>Polymorphism with Inheritance:</strong></p><p>In Python, Polymorphism lets us define 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. However, it is possible to modify a method in a child class that it has inherited from the parent class. This is particularly useful in cases where the method inherited from the parent class doesn’t quite fit the child class. In such cases, we re-implement the method in the child class. This process of re-implementing a method in the child class is known as <strong>Method Overriding</strong>.</p><pre>class Bird:<br>def intro(self):<br> print(&quot;There are many types of birds.&quot;)<br> <br>def flight(self):<br> print(&quot;Most of the birds can fly but some cannot.&quot;)<br><br>class sparrow(Bird):<br>def flight(self):<br> print(&quot;Sparrows can fly.&quot;)<br> <br>class ostrich(Bird):<br>def flight(self):<br> print(&quot;Ostriches cannot fly.&quot;)<br> <br>obj_bird = Bird()<br>obj_spr = sparrow()<br>obj_ost = ostrich()<br><br>obj_bird.intro()<br>obj_bird.flight()<br><br>obj_spr.intro()<br>obj_spr.flight()<br><br>obj_ost.intro()<br>obj_ost.flight()<br><br>Output:<br>There are many types of birds.<br>Most of the birds can fly but some cannot.<br>There are many types of birds.<br>Sparrows can fly.<br>There are many types of birds.<br>Ostriches cannot fly.</pre><p><strong>Polymorphism with a Function and objects:</strong></p><p>It is also possible to create a function that can take any object, allowing for polymorphism. In this example, let’s create a function called “func()” which will take an object which we will name “obj”. Though we are using the name ‘obj’, any instantiated object will be able to be called into this function. Next, let’s give the function something to do that uses the ‘obj’ object we passed to it. In this case, let’s call the three methods, viz., capital(), language() and type(), each of which is defined in the two classes ‘India’ and ‘USA’. Next, let’s create instantiations of both the ‘India’ and ‘USA’ classes if we don’t have them already. With those, we can call their action using the same func():</p><p><strong>Code:</strong> Implementing Polymorphism with a Function</p><pre>class India():<br> def capital(self):<br>  print(&quot;New Delhi is the capital of India.&quot;)<br><br> def language(self):<br>  print(&quot;Hindi is the most widely spoken language of India.&quot;)<br><br> def type(self):<br>  print(&quot;India is a developing country.&quot;)<br><br>class USA():<br> def capital(self):<br>  print(&quot;Washington, D.C. is the capital of USA.&quot;)<br><br> def language(self):<br>  print(&quot;English is the primary language of USA.&quot;)<br><br> def type(self):<br>  print(&quot;USA is a developed country.&quot;)<br><br>def func(obj):<br> obj.capital()<br> obj.language()<br> obj.type()<br><br>obj_ind = India()<br>obj_usa = USA()<br><br>func(obj_ind)<br>func(obj_usa)<br><br>Output:<br>New Delhi is the capital of India.<br>Hindi is the most widely spoken language of India.<br>India is a developing country.<br>Washington, D.C. is the capital of USA.<br>English is the primary language of USA.<br>USA is a developed country.</pre><h4>Simple example of polymorphism:</h4><h4>polymorphism in Python using inheritance and method overriding:</h4><pre>class Animal:<br> def speak(self):<br>  raise NotImplementedError(&quot;Subclass must implement this method&quot;)<br><br>class Dog(Animal):<br> def speak(self):<br>  return &quot;Woof!&quot;<br><br>class Cat(Animal):<br> def speak(self):<br>  return &quot;Meow!&quot;<br><br># Create a list of Animal objects<br>animals = [Dog(), Cat()]<br><br># Call the speak method on each object<br>for animal in animals:<br> print(animal.speak())<br><br><br>Output:<br>Woof!<br>Meow!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8ca4cbca8b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion function in python]]></title>
            <link>https://medium.com/@prasannavadlamudi162611/recursion-753717c366e8?source=rss-ae0fb8ece824------2</link>
            <guid isPermaLink="false">https://medium.com/p/753717c366e8</guid>
            <dc:creator><![CDATA[Prasanna Vadlamudi]]></dc:creator>
            <pubDate>Fri, 22 Dec 2023 10:44:58 GMT</pubDate>
            <atom:updated>2023-12-23T17:13:37.003Z</atom:updated>
            <content:encoded><![CDATA[<p>A function calls itself.It is always made up of two portions the base case and the recursive case.The base case is the condition to stop the recursion,The recursive case is the part where the function calls on itself.</p><p>syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/0*ZcAS7cfbTpKRWE36.png" /></figure><p>-</p><p>#program to print the fibonacci series</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*SjAJgkMw83gvrwjcL9ji7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/194/1*ZJOAN7bmN54WY7jRLhi_UA.png" /><figcaption># function calling</figcaption></figure><p>output:5 # I take 5 as x.In the if condition 5≤1 so the condition is failed then enter into else block</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*4noPcAwFGWxoscKdKML-Jg.png" /></figure><p>Using the above picture to get an idea</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=753717c366e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>