<?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 Harshini M on Medium]]></title>
        <description><![CDATA[Stories by Harshini M on Medium]]></description>
        <link>https://medium.com/@harshinim130?source=rss-839d5e0c7042------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*09E3VoezwZEFOKI0</url>
            <title>Stories by Harshini M on Medium</title>
            <link>https://medium.com/@harshinim130?source=rss-839d5e0c7042------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 20:48:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshinim130/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[COLLECTION IN PYTHON]]></title>
            <link>https://medium.com/@harshinim130/collection-in-python-d10214dd8954?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/d10214dd8954</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Wed, 25 May 2022 10:54:33 GMT</pubDate>
            <atom:updated>2022-05-25T10:54:33.872Z</atom:updated>
            <content:encoded><![CDATA[<p>The collection Module in Python provides different types of containers. A Container is an object that is used to store different objects and provide a way to access the contained objects and iterate over them. Some of the built-in containers are <a href="https://www.geeksforgeeks.org/python-tuples/">Tuple</a>, <a href="https://www.geeksforgeeks.org/python-list/">List</a>, <a href="https://www.geeksforgeeks.org/python-dictionary/">Dictionary</a>, etc. In this article, we will discuss the different containers provided by the collections module. The collections module is a powerful part of the Python standard library that lets you work with data concisely and efficiently. This tutorial covered three of the classes provided by the collections module including <strong>namedtuple , defaultdict , and deque</strong> .</p><h4>The Counter</h4><p><strong>Counter</strong> is a subclass of dictionary object. The Counter() function in collections module takes an iterable or a mapping as the argument and returns a Dictionary. In this dictionary, a key is an element in the iterable or the mapping and value is the number of times that element exists in the iterable or the mapping.</p><p>You have to import the Counter class before you can create a counter instance.</p><pre>from collections import Counter</pre><p>Create Counter Objects</p><p>There are multiple ways to create counter objects. The simplest way is to use Counter() function without any arguments.</p><pre>cnt = Counter()</pre><p>You can pass an iterable (list) to Counter() function to create a counter object.</p><pre>list = [1,2,3,4,1,2,6,7,3,8,1]<br>Counter(list)</pre><p>Finally, the Counter() function can take a dictionary as an argument. In this dictionary, the value of a key should be the &#39;count&#39; of that key.</p><pre>Counter({1:3,2:4})</pre><p>You can access any counter item with its key as shown below:</p><pre>list = [1,2,3,4,1,2,6,7,3,8,1]<br>cnt = Counter(list)<br>print(cnt[1])</pre><p>when you print cnt[1], you will get the count of 1.</p><p><strong>Output:</strong></p><pre>3</pre><p>In the above examples, cnt is an object of Counter class which is a subclass of dict. So it has all the methods of dict class.</p><p>Apart from that, Counter has three additional functions:</p><ol><li>Elements</li><li>Most_common([n])</li><li>Subtract([interable-or-mapping])</li></ol><p>The element() Function</p><p>You can get the items of a Counter object with elements() function. It returns a list containing all the elements in the Counter object.</p><p>Look at the following example:</p><pre>cnt = Counter({1:3,2:4})<br>print(list(cnt.elements()))</pre><p><strong>Output:</strong></p><pre>[1, 1, 1, 2, 2, 2, 2]</pre><p>Here, we create a Counter object with a dictionary as an argument. In this Counter object, count of 1 is 3 and count of 2 is 4. The elements() function is called using cnt object which returns an iterator which is passed as an argument to the list.</p><p>The iterator repeats 3 times over 1 returning three ‘1’s, and repeats four times over 2 returning four ‘2’s to the list. Finally, the list is printed using the print function.</p><p>The most_common() Function</p><p>The Counter() function returns a dictionary which is unordered. You can sort it according to the number of counts in each element using most_common() function of the Counter object.</p><pre>list = [1,2,3,4,1,2,6,7,3,8,1]<br>cnt = Counter(list)<br>print(cnt.most_common())</pre><p><strong>Output:</strong></p><pre>[(1, 3), (2, 2), (3, 2), (4, 1), (6, 1), (7, 1), (8, 1)]</pre><p>You can see that most_common function returns a list, which is sorted based on the count of the elements. 1 has a count of three, therefore it is the first element of the list.</p><p>The subtract() Function</p><p>The subtract() takes iterable (list) or a mapping (dictionary) as an argument and deducts elements count using that argument.</p><h3>Namedtuple:</h3><p>A <a href="https://www.geeksforgeeks.org/namedtuple-in-python/">NamedTuple</a> returns a tuple object with names for each position which the ordinary tuples lack. For example, consider a tuple names student where the first element represents fname, second represents lname and the third element represents the DOB. Suppose for calling fname instead of remembering the index position you can actually call the element by using the fname argument, then it will be really easy for accessing tuples element. This functionality is provided by the NamedTuple.</p><p><strong>Syntax:</strong></p><pre>class collections.namedtuple(typename, field_names)</pre><h3>The defaultdict :</h3><p>The defaultdict works exactly like a python dictionary, except for it does not throw KeyError when you try to access a non-existent key.</p><p>Instead, it initializes the key with the element of the data type that you pass as an argument at the creation of defaultdict. The data type is called default_factory.</p><h4>Import defaultdict:</h4><p>First, you have to import defaultdict from collections module before using it:</p><pre>from collections import defaultdict</pre><h4>Create a defaultdict:</h4><p>You can create a defaultdict with the defaultdict() constructor. You have to specify a data type as an argument. Check the following code:</p><pre>nums = defaultdict(int)<br>nums[&#39;one&#39;] = 1<br>nums[&#39;two&#39;] = 2<br>print(nums[&#39;three&#39;])</pre><p><strong>Output:</strong></p><pre>0</pre><p>In this example, int is passed as the default_factory. Notice that you only pass int, not int(). Next, the values are defined for the two keys, namely, &#39;one&#39; and &#39;two&#39;, but in the next line we try to access a key that has not been defined yet.</p><p>In a normal dictionary, this will force a KeyError. But defaultdict initialize the new key with default_factory&#39;s default value which is 0 for int. Hence, when the program is executed, and 0 will be printed. This particular feature of initializing non-existent keys can be exploited in various situations.</p><p>For example, let’s say you want the count of each name in a list of names given as “Mike, John, Mike, Anna, Mike, John, John, Mike, Mike, Britney, Smith, Anna, Smith”.</p><pre>from collections import defaultdict</pre><pre>count = defaultdict(int)<br>names_list = &quot;Mike John Mike Anna Mike John John Mike Mike Britney Smith Anna Smith&quot;.split()<br>for names in names_list:<br>    count[names] +=1<br>print(count)</pre><p><strong>Output:</strong></p><pre>defaultdict(&lt;class &#39;int&#39;&gt;, {&#39;Mike&#39;: 5, &#39;Britney&#39;: 1, &#39;John&#39;: 3, &#39;Smith&#39;: 2, &#39;Anna&#39;: 2})</pre><p>First, we create a defaultdict with int as default_factory. The names_list includes a set of names which repeat several times. The split() function returns a list from the given string. It breaks the string whenever a white-space is encountered and returns words as elements of the list. In the loop, each item in the list is added to the defaultdict named as count and initialized to 0 based on default_factory. If the same element is encountered again, as loop continues, count of that element will be incremented.</p><h3>Deque:</h3><p>Deque is the optimized list for quicker append and pop operations from both sides of the container. It provides O(1) time complexity for append and pop operations as compared to list with O(n) time complexity.</p><p><strong>Syntax:</strong></p><pre>class collections.deque(list)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d10214dd8954" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DATA TYPES IN PYTHON]]></title>
            <link>https://medium.com/@harshinim130/data-types-in-python-8a39787d53ff?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a39787d53ff</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Thu, 19 May 2022 10:35:19 GMT</pubDate>
            <atom:updated>2022-05-19T10:35:19.410Z</atom:updated>
            <content:encoded><![CDATA[<p>Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.</p><p>Following are the standard or built-in data type of Python:</p><ul><li><a href="https://www.geeksforgeeks.org/python-data-types/#numeric">Numeric</a></li><li><a href="https://www.geeksforgeeks.org/python-data-types/#Sequence">Sequence Type</a></li><li><a href="https://www.geeksforgeeks.org/python-data-types/#boolean">Boolean</a></li><li><a href="https://www.geeksforgeeks.org/python-data-types/#set">Set</a></li><li><a href="https://www.geeksforgeeks.org/python-data-types/#dictionary">Dictionary</a></li></ul><p>Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.</p><h4>Numeric Data Type:-</h4><p>In Python, a numeric data type represents the data that has a numeric value. The numeric value can be an integer, floating number, or even complex number. These values are defined as int, float, and complex classes in Python.</p><p>EXAMPLE:</p><p>a = 2</p><p>print(a, “is of type”, type(a))</p><p>Output: 2 is of type</p><h4>String Data Type:</h4><p>A string is a collection of one or more characters put in a single quote, double-quote, or triple quote. It is represented by an str class.</p><p>Example:-</p><p>string1= “hello everyone”</p><p>print(string1)</p><p>output: hello everyone</p><p>List data type:</p><p>Lists are used to store multiple items in a single variable.</p><p>List items are ordered, changeable, and allow duplicate values.</p><p>List items are indexed, the first item has index [0], the second item has index [1], etc.</p><p>example:</p><p>l1=[1,2,3,4]</p><p>l2=[a,b,c,d]</p><p>print(l1+l2)</p><p>output:</p><p>[1,2,3,4, a, b,c,d]</p><h4>Tuple Data Type:-</h4><p>A tuple is defined as an ordered collection of Python objects. The only difference between tuple and list is that tuples are immutable i.e. tuples can’t be modified after it’s created. It is represented by tuple class. we can represent tuples using parentheses ( )</p><p>example:</p><p>t1=(1,2,3,4)</p><p>t2=(‘a’,’b’,’c’,’d’)</p><p>print(t1+t2)</p><p>output:</p><p>(1, 2, 3, 4, ‘a’, ‘b’, ‘c’, ‘d’)</p><h4>Dictionary:</h4><p>The dictionary is an unordered collection that contains key:value pairs separated by commas inside curly brackets. Dictionaries are optimized to retrieve values when the key is known.</p><p>The following declares a dictionary object.</p><p>Example:</p><p>capitals = {“USA”:”Washington D.C.”, “France”:”Paris”, “India”:”New Delhi”}</p><h4>SET:</h4><p>A set is a collection which is unordered, In Python sets are written with curly brackets. Duplicate values will be ignored.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a39787d53ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EXCEPTION IN PYTHON]]></title>
            <link>https://medium.com/@harshinim130/exception-in-python-44d48efbd31?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/44d48efbd31</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Thu, 19 May 2022 10:14:58 GMT</pubDate>
            <atom:updated>2022-05-19T10:14:58.454Z</atom:updated>
            <content:encoded><![CDATA[<p>An exception can be defined as an unusual condition in a program resulting in the interruption in the flow of the program.</p><p>Whenever an exception occurs, the program stops the execution, and thus the further code is not executed. Therefore, an exception is the run-time errors that are unable to handle to Python script. An exception is a Python object that represents an error</p><p>Python provides a way to handle the exception so that the code can be executed without any interruption. If we do not handle the exception, the interpreter doesn’t execute all the code that exists after the exception.</p><p>Python has many <strong>built-in exceptions</strong> that enable our program to run without interruption and give the output. These exceptions are given below:</p><h3>Common Exceptions</h3><p>Python provides the number of built-in exceptions, but here we are describing the common standard exceptions. A list of common exceptions that can be thrown from a standard Python program is given below.</p><ol><li><strong>ZeroDivisionError:</strong> Occurs when a number is divided by zero.</li><li><strong>NameError:</strong> It occurs when a name is not found. It may be local or global.</li><li><strong>IndentationError:</strong> If incorrect indentation is given.</li><li><strong>IOError:</strong> It occurs when Input Output operation fails.</li><li><strong>EOFError:</strong> It occurs when the end of the file is reached, and yet operations are being performed.</li></ol><p><strong>Zero division error: </strong>we have two variables <strong>a</strong> and <strong>b</strong>, which take the input from the user and perform the division of these values. What if the user entered the zero as the denominator? It will interrupt the program execution and through a <strong>ZeroDivision</strong> exception. Let’s see the following example.</p><h3>Example:</h3><ol><li>a = int(input(“Enter a:”))</li><li>b = int(input(“Enter b:”))</li><li>c = a/b</li><li><strong>print</strong>(“a/b = %d” %c)</li></ol><p><strong>Output:</strong></p><pre>Enter a:10<br>Enter b:0<br>Traceback (most recent call last):<br>  File &quot;exception-test.py&quot;, line 3, in &lt;module&gt;<br>    c = a/b;<br>ZeroDivisionError: division by zero</pre><h3>Exception handling in python</h3><h3>The try-expect statement</h3><p>If the Python program contains suspicious code that may throw the exception, we must place that code in the <strong>try</strong> block. The <strong>try</strong> block must be followed with the <strong>except</strong> statement, which contains a block of code that will be executed if there is some exception in the try block.</p><p><strong>Syntax</strong></p><p><strong>try</strong>:</p><p>#block of code</p><p><strong>except</strong> Exception1:</p><p>#block of code</p><p><strong>except</strong> Exception2:</p><p>#block of code</p><p>#other code</p><p>Consider the following example.</p><ol><li><strong>try</strong>:</li><li>a = int(input(&quot;Enter a:&quot;))</li><li>b = int(input(&quot;Enter b:&quot;))</li><li>c = a/b</li><li><strong>except</strong>:</li><li><strong>print</strong>(&quot;Can&#39;t divide with zero&quot;)</li></ol><p><strong>Output:</strong></p><pre>Enter a:10<br>Enter b:0<br>Can&#39;t divide with zero</pre><p>We can also use the else statement with the try-except statement in which, we can place the code which will be executed in the scenario if no exception occurs in the try block.</p><h3>Raising exceptions</h3><p>An exception can be raised forcefully by using the <strong>raise</strong> clause in Python. It is useful in in that scenario where we need to raise an exception to stop the execution of the program.</p><p>For example, there is a program that requires 2GB memory for execution, and if the program tries to occupy 2GB of memory, then we can raise an exception to stop the execution of the program.</p><p>The syntax to use the raise statement is given below.</p><p><strong>Syntax:</strong></p><p><strong>raise</strong> Exception_class,&lt;value&gt;</p><h3>Custom Exception</h3><p>The Python allows us to create our exceptions that can be raised from the program and caught using the except clause. However, we suggest you read this section after visiting the Python object and classes.</p><p>Consider the following example.</p><p><strong>Example:</strong></p><ol><li><strong>class</strong> ErrorInCode(Exception):</li><li><strong>def</strong> __init__(self, data):</li><li>self.data = data</li><li><strong>def</strong> __str__(self):</li><li><strong>return</strong> repr(self.data)</li><li><strong>try</strong>:</li><li><strong>raise</strong> ErrorInCode(2000)</li><li><strong>except</strong> ErrorInCode as ae:</li><li><strong>print</strong>(“Received error:”, ae.data)</li></ol><p><strong>Output:</strong></p><pre>Received error: 2000</pre><h3>Declaring Multiple Exceptions</h3><p>The Python allows us to declare the multiple exceptions with the except clause. Declaring multiple exceptions is useful in the cases where a try block throws multiple exceptions. The syntax is given below.</p><p>Consider the following example.</p><h4>Example:</h4><ol><li><strong>try</strong>:</li><li>a=10/0;</li><li><strong>except</strong>(ArithmeticError, IOError):</li><li><strong>print</strong>(“Arithmetic Exception”)</li><li><strong>else</strong>:</li><li><strong>print</strong>(“Successfully Done”)</li></ol><p><strong>Output:</strong></p><pre>Arithmetic Exception</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44d48efbd31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DECORATORS]]></title>
            <link>https://medium.com/@harshinim130/decorators-9940e4faa008?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/9940e4faa008</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Thu, 19 May 2022 09:44:43 GMT</pubDate>
            <atom:updated>2022-05-19T09:44:43.136Z</atom:updated>
            <content:encoded><![CDATA[<p>A decorator takes in a function, adds some functionality and returns it.</p><h3>Decorators in Python</h3><p>Python has an interesting feature called <strong>decorators</strong> to add functionality to an existing code. This is also called <strong>metaprogramming</strong> because a part of the program tries to modify another part of the program at compile time.</p><p>In order to understand about decorators, we must first know a few basic things in Python.</p><p>We must be comfortable with the fact that everything in Python (Yes! Even classes), are <a href="https://www.programiz.com/python-programming/class">objects</a>. Names that we define are simply identifiers bound to these objects. <a href="https://www.programiz.com/python-programming/function">Functions</a> are no exceptions, they are objects too (with attributes). Various different names can be bound to the same function object.</p><p>Here is an example.</p><pre>def first(msg):<br>    print(msg)<br></pre><pre>first(&quot;Hello&quot;)</pre><pre>second = first<br>second(&quot;Hello&quot;)</pre><p><strong>Output</strong></p><pre>Hello<br>Hello</pre><p>When you run the code, both functions first and second give the same output. Here, the names first and second refer to the same function object. Now things start getting weirder. Functions can be passed as arguments to another function. If you have used functions like map, filter and reduce in Python, then you already know about this. Such functions that take other functions as arguments are also called <strong>higher order functions</strong>. Here is an example of such a function.</p><pre>def inc(x):<br>    return x + 1<br><br><br>def dec(x):<br>    return x - 1<br><br><br>def operate(func, x):<br>    result = func(x)<br>    return result</pre><p>Furthermore, a function can return another function.</p><pre>def is_called():<br>    def is_returned():<br>        print(&quot;Hello&quot;)<br>    return is_returned<br></pre><pre>new = is_called()</pre><pre># Outputs &quot;Hello&quot;<br>new()</pre><p><strong>Output</strong></p><pre>Hello</pre><p><em>Here, </em><em>is_returned() is a nested function which is defined and returned each time we call </em><em>is_called(). Finally, we must know about Closures in Python.</em></p><h3>About Decorators :</h3><p>Functions and methods are called <strong>callable</strong> as they can be called.</p><p>In fact, any object which implements the special __call__() method is termed callable. So, in the most basic sense, a decorator is a callable that returns a callable.</p><p>Basically, a decorator takes in a function, adds some functionality and returns it.</p><pre>def make_pretty(func):<br>    def inner():<br>        print(&quot;I got decorated&quot;)<br>        func()<br>    return inner<br><br><br>def ordinary():<br>    print(&quot;I am ordinary&quot;)</pre><p>When you run the following codes in shell.</p><pre>&gt;&gt;&gt; ordinary()<br>I am ordinary<br><br>&gt;&gt;&gt; # let&#39;s decorate this ordinary function<br>&gt;&gt;&gt; pretty = make_pretty(ordinary)<br>&gt;&gt;&gt; pretty()<br>I got decorated<br>I am ordinary</pre><p>In the example shown above, make_pretty() is a decorator. In the assignment step:</p><pre>pretty = make_pretty(ordinary)</pre><p>The function ordinary() got decorated and the returned function was given the name pretty.</p><p>We can see that the decorator function added some new functionality to the original function. This is similar to packing a gift. The decorator acts as a wrapper. The nature of the object that got decorated (actual gift inside) does not alter. But now, it looks pretty (since it got decorated).</p><p>Generally, we decorate a function and reassign it as,</p><pre>ordinary = make_pretty(ordinary).</pre><p>This is a common construct and for this reason, Python has a syntax o simplify this.</p><p>We can use the @ symbol along with the name of the decorator function and place it above the definition of the function to be decorated. For example,</p><pre>@make_pretty<br>def ordinary():<br>    print(&quot;I am ordinary&quot;)</pre><p>is equivalent to</p><pre>def ordinary():<br>    print(&quot;I am ordinary&quot;)<br>ordinary = make_pretty(ordinary)</pre><p>This is just a syntactic sugar to implement decorators.</p><h3>How to Add Arguments to Decorators in Python</h3><p>Decorators can have arguments passed to them. To add arguments to decorators I add *args<em> </em>and<em> </em><em>*</em>*kwargs to the inner functions.</p><ul><li>*<strong>args</strong> will take an unlimited number of arguments of any type, such as 10, True, or &#39;Brandon&#39;.</li><li>**<strong>kwargs</strong> will take an unlimited number of keyword arguments, such as count=99, is_authenticated=True, or name=&#39;Brandon&#39;.</li></ul><p>Here is a decorator with arguments:</p><pre>from functools import wraps<br><br>def my_decorator_func(func):<br><br>    @wraps(func)<br>    def wrapper_func(*args, **kwargs):<br>        func(*args, **kwargs)<br>    return wrapper_func<br><br>@my_decorator_func<br>def my_func(my_args):<br>    &#39;&#39;&#39;Example docstring for function&#39;&#39;&#39;<br><br>    pass</pre><h4>output:</h4><pre>print(my_func.__name__)<br>print(my_func.__doc__)<br><br># Output<br><br>my_func<br>Example docstring for function</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9940e4faa008" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[POLYMORPHISM]]></title>
            <link>https://medium.com/@harshinim130/polymorphism-ed38d800edeb?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed38d800edeb</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Mon, 16 May 2022 10:41:43 GMT</pubDate>
            <atom:updated>2022-05-16T10:41:43.664Z</atom:updated>
            <content:encoded><![CDATA[<p>polymorphism is an important feature of class definition in Python that is utilized when you have commonly named methods across classes or sub classes. Polymorphism can be carried out through inheritance, with sub classes making use of base class methods or overriding them.</p><p>There are two types of polymorphism:</p><p>1.Overloading</p><p>2.Overriding</p><h3><strong>Overloading:</strong></h3><p>Overloading occurs when two or more methods in one class have the same method name but different parameters.</p><p>Overloading is divided into two types</p><p><strong>.</strong>Operator Overloading</p><p><strong>.</strong> Method Overloading</p><p>Operator overloading: Operator overloading is the type of overloading in which an operator can be used in multiple ways beyond its predefined meaning.</p><p>Method Overloading: Method overloading means a class containing multiple methods with the same name but may have different arguments. Basically python does not support method overloading, but there are several ways to achieve method overloading. Though method overloading can be achieved, the last defined methods can only be usable.</p><h3><strong>Polymorphism with Function and Objects:</strong></h3><p>You can create a function that can take any <a href="https://www.edureka.co/blog/python-class/#Objects">object</a>, allowing for polymorphism.</p><p>Let’s take an example and create a function called “<strong>func()</strong>” which will take an object which we will name “obj”. Now, let’s give the function something to do that uses the ‘<strong>obj</strong>’ object we passed to it. In this case, let’s call the methods <strong>type()</strong> and <strong>color()</strong>, each of which is defined in the two classes ‘Tomato’ and ‘Apple’. Now, you have to create instantiations of both the ‘Carrot’ and ‘Apple’ classes if we don’t have them already:</p><p><strong>class carrot</strong>():</p><p><strong>def</strong> type(self):</p><p>print(&quot;Vegetable&quot;)</p><p><strong>def</strong> color(self):</p><p>print(&quot;orange&quot;)</p><p><strong>class</strong> Apple():</p><p><strong>def</strong> type(self):</p><p>print(&quot;Fruit&quot;)</p><p><strong>def</strong> color(self):</p><p>print(&quot;Red&quot;)</p><p><strong>def</strong> func(obj):</p><p>obj.type()</p><p>obj.color()</p><p>obj_carrot <strong>= carrot</strong>()</p><p>obj_apple <strong>=</strong> Apple()</p><p>func(obj_tomato)</p><p>func(obj_apple)</p><p><strong>Output:</strong></p><pre>Vegetable<br>Orange<br>Fruit<br>Red</pre><h3>Polymorphism with Class Methods</h3><p>Python uses two different class types in the same way. Here, you have to create a <a href="https://www.edureka.co/blog/videos/python-loops/">for loop</a> that iterates through a <strong>tuple</strong> of objects. Next, you have to call the methods without being concerned about which class type each object is. We assume that these methods actually exist in each class. Example for class method:</p><p>class Car():</p><p>def wheels(self):</p><p>print(3)</p><p>def mode_of_transport(self):</p><p>print(“Public”)</p><p>class Bus():</p><p>def wheels(self):</p><p>print(9)</p><p>def mode_of_transport(self):</p><p>print(“Private”)</p><p>obj_car = Car()</p><p>obj_bus = Bus()</p><p>for vehicle in (obj_car, obj_bus):</p><p>vehicle.wheels()</p><p>vehicle.mode_of_transport()</p><h3>Output</h3><p>3</p><p>public</p><p>9</p><p>private</p><h3>Inheritance</h3><p>Before we get into method overriding, it’s necessary to understand Python’s initial inheritance. Inheritance is the method by which a class may be derived from any base class, with the derived class inheriting all of the base class’s attributes. Inheritance alleviates the challenge of repeatedly writing the same code and enhances reusability.</p><p><strong>Example of inheritance:</strong></p><pre>class Bird://base class Bird<br>    def sound(self):<br>        print(&quot;Birds Sounds&quot;)<br>#сhild сlаss Dоg inherits the bаse сlаss Аnimаl<br>class Sparrow(Bird)://child class Sparrow<br>    def tweet(self):<br>        print(&quot;sparrow tweeting&quot;)<br>d = Sparrow()<br>d.tweet()<br>d.sound()</pre><p><strong>Output:</strong></p><pre>Sparrow tweeting<br>Birds Sound</pre><h3>Method Overriding:</h3><p>Overriding means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class.</p><p>There are different methods to use polymorphism in Python. You can use different function,<a href="https://www.edureka.co/blog/python-class/"> class methods</a> or objects to define the polymorphism.</p><p>class Bird:<br>def intro(self):<br> print(“There are many types of birds.”)<br> <br>def flight(self):<br> print(“Most of the birds can fly but some cannot.”)</p><p>class sparrow(Bird):<br>def flight(self):<br> print(“Sparrows can fly.”)<br> <br>class ostrich(Bird):<br>def flight(self):<br> print(“Ostriches cannot fly.”)<br> <br>obj_bird = Bird()<br>obj_spr = sparrow()<br>obj_ost = ostrich()</p><p>obj_bird.intro()<br>obj_bird.flight()</p><p>obj_spr.intro()<br>obj_spr.flight()</p><p>obj_ost.intro()<br>obj_ost.flight()</p><p><strong>Output:</strong></p><pre>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><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed38d800edeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OBJECT ORIENTED CONCEPTS IN PYTHON]]></title>
            <link>https://medium.com/@harshinim130/object-oriented-concepts-in-python-a04a1672c64?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/a04a1672c64</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Mon, 09 May 2022 12:48:41 GMT</pubDate>
            <atom:updated>2022-05-09T12:48:41.863Z</atom:updated>
            <content:encoded><![CDATA[<p>In Python, object-oriented Programming (OOPs) is a programming paradigm that uses objects and classes in programming. It aims to implement real-world entities like inheritance, polymorphisms, encapsulation, etc. in the programming. The main concept of OOPs is to bind the data and the functions that work on that together as a single unit so that no other part of the code can access this data.</p><h3>Main Concepts of Object-Oriented Programming (OOPs)</h3><ul><li>Class</li><li>Objects</li><li>Polymorphism</li><li>Encapsulation</li><li>Inheritance</li></ul><p><strong>CLASS:</strong></p><p>A class is a collection of objects. Unlike the primitive data structures, classes are data structures that the user defines. They make the code more manageable. Let’s see how to define a class below-</p><pre>class class_name:<br>    class body</pre><p>We define a class with a keyword “class” following the class_name and colon. And we consider everything you write under this after using indentation as its body.</p><p><strong>OBJECT:</strong></p><p>When we define a class only the description or a blueprint of the object is created. There is no memory allocation until we create its <strong>object</strong>. The <strong>objector</strong> <strong>instance</strong> contains real data or information. Instantiation is nothing but creating a new object/instance of a class. Let’s create the object of the above class we defined-</p><pre>obj1 = flower()</pre><p><strong>POLYMORPHISM:</strong></p><p>This is a Greek word. If we break the term Polymorphism, we get “poly”-many and “morph”-forms. So Polymorphism means having many forms. In OOP it refers to the functions having the same names but carrying different functionalities. It describes the concept wherein you can use different classes with the same interface. Each of these classes can provide its own implementation of the interface.</p><p><strong>ENCAPSULATION:</strong></p><p>In Object Oriented Programming, Encapsulation is defined as <strong>binding together the data and the functions that manipulates them</strong>. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing direct access to them by clients in a way that could expose hidden implementation details or violate state invariance maintained by the methods.</p><p><strong>INHERITENCE:</strong></p><p>Inheritance is the procedure in which one class inherits the attributes and methods of another class. The class whose properties and methods are inherited is known as Parent class. And the class that inherits the properties from the parent class is the Child class. The interesting thing is, along with the inherited properties and methods, a child class can have its own properties and methods. How to inherit a parent class? Use the following syntax:</p><pre>class parent_class:<br>body of parent class</pre><pre>class child_class( parent_class):<br>body of child class</pre><p>These are some basic concept of oops in python.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a04a1672c64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[USE OF BREAK, CONTINUE AND PASS]]></title>
            <link>https://medium.com/@harshinim130/use-of-break-continue-and-pass-f4fef2be6287?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4fef2be6287</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Thu, 05 May 2022 17:11:50 GMT</pubDate>
            <atom:updated>2022-05-05T17:11:50.090Z</atom:updated>
            <content:encoded><![CDATA[<p>In python concept of loops helps to iterate over a list, tuple, string, dictionary, set. There are two types of loop supported in Python “for” and “while”. The block of code is executed multiple times inside the loop until the condition fails. Python break and continue are used inside the loop to change the flow of the loop from its standard procedure. A for-loop or while-loop is meant to iterate until the condition given fails. When you use a break or continue statement, the flow of the loop is changed from its normal way.</p><p><strong>BREAK STATEMENT:</strong></p><p>The break statement takes care of terminating the loop in which it is used. If the break statement is used inside nested loops, the current loop is terminated, and the flow will continue with the code followed that comes after the loop. If the break statement is associated with a conditional if statement, then it will execute only when the condition of the if the statement is evaluated to true. If the break statement is not associated with any conditional statement within a loop, then it will just exit the loop right when it is encountered for the first time. The break statement allows you to exit a loop from any point within its body, bypassing its normal <strong>termination</strong> expression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/0*HjdT2DDfPdo2oAub.png" /></figure><p><strong>CONTINUE STATEMENT:</strong></p><p>The continue statement is used to skip the remaining code inside a loop for the current iteration only and moves the control back to the top of the loop. The continue statement can be used in both while and for loops. It is mainly used for a particular condition inside the loop so that we can skip some specific code for a particular condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/0*G8AvSxGLi7Eae1S1.jpg" /></figure><h4>PASS STATEMENT:</h4><ul><li>Pass Statement is used when a statement is required syntactically but you do not want any command or code to execute. The <strong>pass</strong> statement is a <em>null</em> operation; nothing happens when it executes. The <strong>pass</strong> statement is also useful in places where your code will eventually go, but has not been written yet i.e. in stubs. The pass statement can be used inside the body of a function or class body. During execution, the interpreter, when it comes across the pass statement, ignores and continues without giving any error.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4fef2be6287" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[APPLICATIONS OF PYTHON]]></title>
            <link>https://medium.com/@harshinim130/applications-of-python-6706ae36b1e6?source=rss-839d5e0c7042------2</link>
            <guid isPermaLink="false">https://medium.com/p/6706ae36b1e6</guid>
            <dc:creator><![CDATA[Harshini M]]></dc:creator>
            <pubDate>Wed, 04 May 2022 17:13:06 GMT</pubDate>
            <atom:updated>2022-05-04T17:13:06.098Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*kJnwVbj9oJw53atc5ONAMg.jpeg" /></figure><p>Python is a very readable language and it is a expressive and high level programming language, which means it is easy to understand the language and thus easy to learn. Python is a open source programming language. Python comes with a large standard library that has some handy codes and functions which we can use while writing code in Python. Python is available and can run on various operating systems such as Mac, Windows, Linux, Unix etc. This makes it a cross platform and portable language.</p><p>Applications of python:</p><p>The applications of python are:</p><ul><li><a href="https://www.edureka.co/blog/python-applications/#web">Web Development</a></li><li><a href="https://www.edureka.co/blog/python-applications/#game">Game Development</a></li><li><a href="https://www.edureka.co/blog/python-applications/#mlai">Machine Learning and Artificial Intelligence</a></li><li><a href="https://www.edureka.co/blog/python-applications/#dsdv">Data Science and Data Visualization</a></li><li><a href="https://www.edureka.co/blog/python-applications/#webs">Web Scraping Applications</a></li><li><a href="https://www.edureka.co/blog/python-applications/#ba">Business Applications</a></li><li><a href="https://www.edureka.co/blog/python-applications/#avapp">Audio and Video Applications</a></li><li><a href="https://www.edureka.co/blog/python-applications/#cad">CAD Applications</a></li><li><a href="https://www.edureka.co/blog/python-applications/#embedded">Embedded Applications</a></li></ul><p><strong>WEB DEVELOPMENT</strong> : Python can be used to make <a href="https://www.edureka.co/blog/django-tutorial/">web-applications</a> at a rapid rate. There is <em>common-backend logic</em> that goes into making these frameworks and a number of libraries that can help integrate protocols such as HTTPS, FTP, SSL and even helps in the processing of JSON, XML, E-Mail and so much more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qyHgF2j7tmHsEF3u3qL_Kw.jpeg" /></figure><p>Web framework like Django and Flask are based on Python. They help you write server side code which helps you manage database, write backend programming logic, mapping urls etc.</p><p><strong>GAME DEVELOPMENT</strong> :Python is also used in the development of <a href="https://www.edureka.co/blog/python-turtle-module/">interactive games</a>. Python provides a built-in library called pygame, which used to develop the game. Once we understand the basic concepts of Python programming, we can use the pygame library to make games with attractive graphics, suitable animation, and sound.Games such as Civilization-IV, Disney’s Toontown Online, Vega Strike etc. have been built using Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*fIsMic5zdSBUKJQFet9aDQ.jpeg" /></figure><p><strong>MACHINE LEARNING ANDARTIFICAL INTELLIGENCE:</strong> <a href="https://www.edureka.co/blog/machine-learning-career/">Machine Learning</a> and <a href="https://www.edureka.co/blog/pros-and-cons-of-ai/">Artificial Intelligence</a> are very interesting as they yield the most promising careers for the future. There are many machine learning applications written in Python. Machine learning is a way to write a logic so that a machine can learn and solve a particular problem on its own. Face recognition and Voice recognition in your phone is another example of machine learning. It support for the domains with the <strong>libraries</strong> that exist already such as <a href="https://www.edureka.co/blog/python-pandas-tutorial/">Pandas</a>, <a href="https://www.edureka.co/blog/scikit-learn-machine-learning/">Scikit-Learn</a>, <a href="https://www.edureka.co/blog/python-numpy-tutorial/">NumPy</a> and so many more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*6eP55TncMSq3EN1or1R39g.jpeg" /></figure><p><strong>DATA SCIENCE : </strong>Data is <em>money</em> if you know how to extract relevant information which can help you take calculated risks and increase profits. You study the data you have, perform operations and extract the information required. You can even visualize the data libraries such as <a href="https://www.edureka.co/blog/python-matplotlib-tutorial/">Matplotlib</a>, <a href="https://www.edureka.co/blog/python-seaborn-tutorial/">Seaborn</a>, which are helpful in <strong>plotting graphs</strong> and much more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*oEuutKy9yknZv3qxnmZDhA.jpeg" /></figure><p><strong>EMBEDDED APPLICATION : </strong>Python is based on C which means that it can be used to create <a href="https://www.edureka.co/blog/embedded-c-programming/">Embedded C</a> software for embedded applications. This helps us to perform higher-level applications on smaller devices which can compute Python. The most well-known embedded application could be the <a href="https://www.edureka.co/blog/raspberry-pi-tutorial/">Raspberry Pi</a> which uses Python for its computing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*9j9SmCiCr_3qH82Uhd10AA.jpeg" /></figure><p><strong>BUSINESS APPLICATION: </strong>Python offers excellent security and scalability features that make it perfect for delivering high-performance business applications. It has inbuilt libraries and tools like:</p><ul><li><em>Odoo is business management software that provides you with an automated solution for your business process.</em></li><li><em>Tryton is easy-to-use open-source business software. It has fully integrated features like financial accounting, sales, CRM, purchasing, shipping, and the list goes on.</em></li></ul><p>All these distinguishing features make it fit for creating business applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*whggWWDWDCyrsGxKVugYEw.jpeg" /></figure><p>We use python in a variety of applications. Python is a concise and extremely powerful language that is rapidly gaining popularity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6706ae36b1e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>