<?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"><channel><title><![CDATA[Blogs]]></title><description><![CDATA[Writing blogs is an art, So i do it.!!]]></description><link>https://cbum-dev.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 22 Oct 2026 03:26:21 GMT</lastBuildDate><atom:link href="https://cbum-dev.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How To Create REST API Using Django]]></title><description><![CDATA[API is the way by which systems communicate with each other. APIs can be used for various purposes, such as accessing web services, retrieving data from…]]></description><link>https://cbum-dev.hashnode.dev/how-to-create-rest-api-using-django</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/how-to-create-rest-api-using-django</guid><category><![CDATA[Python]]></category><category><![CDATA[Django]]></category><category><![CDATA[APIs]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Mon, 25 Dec 2023 15:00:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/ehyV_XOZ4iA/upload/6ef2dbcd8d4caccde47fe8d18f4962bc.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h2 id="heading-what-is-a-restrepresentational-state-transfer-api"><strong>What is a REST(Representational State Transfer) API?</strong></h2>
<p>API is the way by which systems communicate with each other. APIs can be used for various purposes, such as accessing web services, retrieving data from databases, or connecting different components of a software application. Rest API (also known as RESTful API) use standard HTTP methods (GET,PUT,PATCH,DELETE,POST) to perform operations. They are widely used in web development. It uses JSON(JavaScript Object Notation) as its message format which is platform independent language.</p>
<p>Their are different types of web APIS eg. (SOAP which uses XML as their message format, Open APIs or public APIs that are accessible to external developers and general public.)</p>
<p><img src="https://raw.githubusercontent.com/Codecademy/articles/0b631b51723fbb3cc652ef5f009082aa71916e63/images/rest_api.svg" alt /></p>
<p>Well their are so many public APIs to use for many purposes. But you can create your own APIs as well and now we'll understand how to make it using Django .</p>
<h2 id="heading-making-rest-api-using-django"><strong>Making REST API using Django</strong></h2>
<ul>
<li><h3 id="heading-installation"><strong>Installation :</strong></h3>
</li>
</ul>
<ol>
<li><p>Make a virtual environment to make things separate from system.</p>
</li>
<li><p>Activate it and install Django and Django-rest-framework.</p>
</li>
<li><p>Make a new Django project .</p>
<pre><code class="lang-plaintext"> python3 -m venv venv 
 ./venv/bin/activate #to activate it 
 pip install djangorestframework #this will also install django and djangorestframework
 django-admin startproject &lt;project name&gt;
 python manage.py startapp api #making your app
 python manage.py runserver #server started at localhost:8000
</code></pre>
<pre><code class="lang-plaintext"> python manage.py makemigrations
 python manage.py migrate
 python manage.py createsuperuser #to access the admin panel
 python manage.py runserver #go to localhost:8000/admin/
</code></pre>
</li>
</ol>
<ul>
<li><h3 id="heading-making-model-and-changing-settings"><strong>Making model and changing settings :</strong></h3>
</li>
</ul>
<ol>
<li><p>We'll create a basic model for students with name and age only.</p>
</li>
<li><p>Go to the <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/"><strong>Settings.py</strong></a> file in the project folder and add your <strong>App name and package</strong> to it.</p>
</li>
</ol>
<pre><code class="lang-plaintext">INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'api', #added app name
    'rest_framework' #installed package
]
</code></pre>
<ol>
<li>Create models in <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/"><strong>models.py</strong></a> in api app.</li>
</ol>
<pre><code class="lang-plaintext">from django.db import models
​
class Student(models.Model):
    name = models.CharField(max_length = 250)
    age = models.IntegerField()

    def __str__(self):  #for convenience in the admin panel
        return self.name
</code></pre>
<ol>
<li>Now run these commands in terminal to migrate the the created model to Database.</li>
</ol>
<pre><code class="lang-plaintext">python manage.py makemigrations
python manage.py migrate
</code></pre>
<ol>
<li><p>Add some random data in the admin panel at <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/"><strong>localhost:8000/admin</strong></a>.</p>
</li>
<li><p>Create a new file <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/"><strong>serializers.py</strong></a> in the api app. <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/">Serializers.py</a> basically serializes the data which you want to get or post in the JSON format.</p>
</li>
</ol>
<pre><code class="lang-plaintext">from .models import Student
from rest_framework import serializers
​
​
class StudentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Student #the model which you want to serialise
        fields = '__all__' #fields you want. if want to add specific field do this ['field1','field2']
</code></pre>
<ol>
<li>Now in the <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/"><strong>views.py</strong></a> and add your logics.</li>
</ol>
<pre><code class="lang-plaintext">from django.shortcuts import render
from rest_framework import generics
from .models import Student
from .serializers import StudentSerializer
​
class StudentView(generics.ListCreateAPIView):
    queryset = Student.objects.all() #same like sql queries
    serializer_class = StudentSerializer #serialising the data
</code></pre>
<ol>
<li>Now in the <a target="_blank" href="https://www.django-rest-framework.org/tutorial/quickstart/">urls.py</a> add your routes.</li>
</ol>
<pre><code class="lang-plaintext">from django.urls import path,include
from .views import StudentView
​
urlpatterns = [
    path('student/',StudentView.as_view(),name='student'),
]
</code></pre>
<ol>
<li><p>Now you can test your created url in Browser. Just simply open the browser and type <strong>127.0.0.1:8000/student/</strong> and all set !</p>
</li>
<li><p>Here, You can get as well post a new data of student.</p>
</li>
</ol>
<h2 id="heading-conclusion"><strong>Conclusion :</strong></h2>
<p>In this way you can create APIs using Django. You can add logic as well to protect your data, add specific logic for your data. You can read official documentation for more knowledge.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Understanding the OSI Model]]></title><description><![CDATA[OSI(Open System Interconnection) model is a conceptual model created to communicate over the network. Although the modern Internet is not based truly on…]]></description><link>https://cbum-dev.hashnode.dev/understanding-the-osi-model</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/understanding-the-osi-model</guid><category><![CDATA[WeMakeDevs]]></category><category><![CDATA[@wemakedev]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Wed, 23 Aug 2023 17:16:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/ISG-rUel0Uw/upload/220c38b0082241203563358bf856a603.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h2 id="heading-overview"><strong>OVERVIEW:</strong></h2>
<p>OSI(Open System Interconnection) model is a conceptual model created to communicate over the network. Although the modern Internet is not based truly on the OSI model but on a simpler <a target="_blank" href="https://www.geeksforgeeks.org/tcp-ip-model/">TCP/IP</a> model.</p>
<h3 id="heading-history"><strong>HISTORY:</strong></h3>
<p>OSI model was introduced in 1983 by major computer and telecom companies. Later adopted by ISO(International Organisation for Standardization) as an international standard in 1984.</p>
<p><img src="https://cdn.educba.com/academy/wp-content/uploads/2019/07/OSI-Model.png.webp" alt /></p>
<hr />
<h2 id="heading-layers-of-osi-model"><strong>LAYERS OF OSI MODEL:</strong></h2>
<p>OSI model consists of 7 layers :</p>
<ol>
<li><p>Application Layer</p>
</li>
<li><p>Presentation Layer</p>
</li>
<li><p>Session Layer</p>
</li>
<li><p>Transport Layer</p>
</li>
<li><p>Network Layer</p>
</li>
<li><p>Data Link Layer</p>
</li>
<li><p>Physical Layer</p>
<hr />
</li>
</ol>
<h3 id="heading-1-application-layer"><strong>1. APPLICATION LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/2rcDKpr4WLqoyAZ7GDKkyJ/7cab96402de7ac5465b86e617da3da4e/osi_model_application_layer_7.png" alt class="image--center mx-auto" /></p>
<p>It is present at the top of the OSI model used by network applications like Chrome, Firefox, G-mail etc. An application layer is not an application, but it performs the application layer functions.</p>
<h5 id="heading-function"><strong>FUNCTION:</strong></h5>
<ul>
<li>FILE TRANSFER, ACCESS AND MANAGEMENT: An application layer allows users to access the files in a remote computer, to retrieve files from a computer.</li>
</ul>
<h5 id="heading-protocols-used"><strong>PROTOCOLS USED:</strong></h5>
<p>A few application layer protocols are <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwi7p_n9numAAxVwZ_UHHYEZCmkQFnoECBkQAQ&amp;url=https%3A%2F%2Fwww.cloudflare.com%2Flearning%2Fddos%2Fglossary%2Fhypertext-transfer-protocol-http%2F&amp;usg=AOvVaw0pDisNY__S-Jfnj0EXZnUC&amp;opi=89978449">HTTP</a> (Hypertext Transfer Protocol) for web surfing, <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiyxsqdoOmAAxXLP3AKHaRoCCwQFnoECBUQAQ&amp;url=https%3A%2F%2Fwww.javatpoint.com%2Fcomputer-network-ftp&amp;usg=AOvVaw2NNT_kpVuDnSoS_fHFl752&amp;opi=89978449">FTP</a> (File Transfer Protocol) for file transferring, <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwityYqhoOmAAxXZfXAKHay4A0gQFnoECBcQAw&amp;url=https%3A%2F%2Fwww.techtarget.com%2Fwhatis%2Fdefinition%2FSMTP-Simple-Mail-Transfer-Protocol&amp;usg=AOvVaw0dynYEFXntHg8DbU_SoJ4w&amp;opi=89978449">SMTP</a> (Simple Mail Transfer Protocol) for mail sending and receiving, <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiU2_ijoOmAAxUGB4gKHbbGCjkQFnoECBcQAQ&amp;url=https%3A%2F%2Fwww.cloudflare.com%2Flearning%2Fdns%2Fwhat-is-dns%2F&amp;usg=AOvVaw0ZNPBtLlK-CpUu_FS4yYVq&amp;opi=89978449">DNS</a> (Domain Name System) for converting domain names like <a target="_blank" href="http://www.google.com">www.google.com</a> to its IP 197.193.232.3. etc.</p>
<h3 id="heading-2-presentation-layer"><strong>2. PRESENTATION LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/19L86neKKT8srUkOSe4rf7/ff4c91c94a1790651df7b48433913f59/osi_model_presentation_layer_6.png" alt /></p>
<p>It receives data from the application layer. This layer serves as a data translator for the network. Data received is manipulated here.</p>
<h5 id="heading-functions"><strong>FUNCTIONS:</strong></h5>
<ul>
<li><p>TRANSLATION: In this process, the data gets converted into a simple binary form.</p>
</li>
<li><p>DATA COMPRESSION: It can be lossy or lossless. In lossy, the significant piece of data is removed to reduce size. While in lossless the data is transformed through encoding and then its size gets reduced.</p>
</li>
<li><p>ENCRYPTION/DECRYPTION: Here the data is encrypted by the sender's side and decrypted by the receiver's side. As the data may often be sensitive, scrambling the data and then putting back together is Encryption and decryption.</p>
</li>
</ul>
<h5 id="heading-protocols-used-1"><strong>PROTOCOLS USED:</strong></h5>
<p>A few presentation layer protocols are <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjx_8_9p-mAAxVUbN4KHUQgD4sQFnoECA4QAw&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FApple_Filing_Protocol&amp;usg=AOvVaw0EYhho7Bpt7EN9jPArw_No&amp;opi=89978449">AFP</a> (Apple Filing Protocol) is a network control protocol that offers services to macOS, <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiWvO-kqOmAAxUQfXAKHYneDDkQFnoECBAQAw&amp;url=https%3A%2F%2Fwww.microfocus.com%2Fdocumentation%2Fopen-enterprise-server-developer-documentation%2Fncp%2F&amp;usg=AOvVaw2N1T0RODnCu54EFdaeGv6T&amp;opi=89978449">NCP</a> (NetWare Core Protocol) is used to access files, print, clock synchronization, messaging etc., <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjd5uLfp-mAAxVvilYBHUFLCVUQFnoECBIQAQ&amp;url=https%3A%2F%2Fwww.cloudflare.com%2Flearning%2Fssl%2Fwhat-is-ssl%2F&amp;usg=AOvVaw03MDTmIOrXkqlhRbSldkgH&amp;opi=89978449">SSL</a> (Secure Socket Layer) is used to provide security to data that is being transferred between the web browser and the server.</p>
<h3 id="heading-3-session-layer"><strong>3. SESSION LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/29mRrgK22AqJVlg2MMlD86/34d8f4071b6cc0d3b03c93f55e4d89b7/osi_model_session_layer_5.png" alt /></p>
<p>These layers help in establishing sessions between different machines. It helps in maintaining, and terminating sessions between end-user applications.</p>
<h5 id="heading-functions-1"><strong>FUNCTIONS:</strong></h5>
<ul>
<li><p>AUTHENTICATION: To establish a connection within the server. To know whether the other end-user is a legitimate one.</p>
</li>
<li><p>AUTHORISATION: In this, although authentication of the user is done but you cannot access the files or data to which you are not authenticated.</p>
</li>
<li><p>SESSION MANAGEMENT: The session layer helps in managing a session which includes opening, closing and managing sessions.</p>
</li>
</ul>
<h5 id="heading-protocols-used-2"><strong>PROTOCOLS USED:</strong></h5>
<p>A few Session layer protocols are <a target="_blank" href="https://www.geeksforgeeks.org/adsp-fullform/">ADSP</a> (Apple-Talk Data Stream Protocol) which allows to LAN to be connected with no setup, <a target="_blank" href="https://www.geeksforgeeks.org/real-time-transport-control-protocol-rtcp/">RTCP</a> (Real-Time Transport Control Protocol) which provides feedback on the Quality of service, <a target="_blank" href="https://www.geeksforgeeks.org/password-authentication-protocol-pap/">PAP</a> (Password Authentication Protocol) which is used by <a target="_blank" href="https://www.geeksforgeeks.org/pptp-full-form/">PPTP</a> (Point to Point Tunnelling Protocol) to validate users, etc.</p>
<h4 id="heading-note"><strong>NOTE:</strong></h4>
<p><em>ALL THE ABOVE 3 LAYER'S FUNCTIONS ARE PERFORMED BY THE BROWSER ITSELF.</em></p>
<hr />
<h3 id="heading-4-transport-layer"><strong>4. TRANSPORT LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/3OlO75NcADGL3SmEADFDqd/723b8c7639c4e2e6b4febcbe7fd36e0e/osi_model_transport_layer_4.png" alt /></p>
<p>This layer takes data from the session layer and breaks it into <em>segments</em> on the sender's end. On the receiver's end, it reassembles the segments. It also checks how much data is being transported. This layer also checks if the data sent is correct or not.</p>
<h5 id="heading-functions-2"><strong>FUNCTIONS:</strong></h5>
<ul>
<li><p>SEGMENTATION: It is the process of dividing a data packet into smaller units over the network. It then reassembles at the destination.</p>
</li>
<li><p>FLOW CONTROL: It means sending the data to a rate that the receiver is capable of.</p>
</li>
<li><p>ERROR CONTROL: This keeps an eye on missing segments or duplicate segments.</p>
</li>
</ul>
<h5 id="heading-protocols-used-3"><strong>PROTOCOLS USED:</strong></h5>
<p><a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwipwvGEjPGAAxUZ1jgGHfz3DpcQFnoECBUQAw&amp;url=https%3A%2F%2Fwww.fortinet.com%2Fresources%2Fcyberglossary%2Ftcp-ip&amp;usg=AOvVaw1bExX3FTi8Q7_dUkMb_gUA&amp;opi=89978449">TCP</a> (Transport Control Protocol) provides data transfer without any loss that can be used for emails etc., <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjAjNCGjPGAAxVC1TgGHXlDDIEQFnoECBEQAw&amp;url=https%3A%2F%2Fwww.techtarget.com%2Fsearchnetworking%2Fdefinition%2FUDP-User-Datagram-Protocol&amp;usg=AOvVaw1JRsIhTmIcB2ExHyCD-Igz&amp;opi=89978449">UDP</a> (User Datagram Protocol) provides data transfer with some loss possible that can be used for video calls etc.</p>
<h3 id="heading-5-network-layer"><strong>5. NETWORK LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/3g2Hv0frHsql5SFauJL5EG/d8cede7b6a780e63413bd86de9eee7f9/osi_model_network_layer_3.png" alt /></p>
<p>The transport layer passes data segments to the network layer. It is the layer where the router resides. This layer is responsible for the transfer of network packets from source to destination. It sets the best path for the data to travel.</p>
<h5 id="heading-functions-3"><strong>FUNCTIONS:</strong></h5>
<ul>
<li><p>LOGIC ADDRESSING: IP addressing done in the network layer is called logical addressing.</p>
</li>
<li><p>PATH DETERMINATION: Choosing the best possible path to transfer the data from one computer to another.</p>
</li>
<li><p>ROUTING: Routing is a method of moving data packets from source to destination. Based on the IP address format the data packet will first move to the network of the receiver and then into their system.</p>
</li>
</ul>
<h5 id="heading-protocols-used-4"><strong>PROTOCOLS USED:</strong></h5>
<p><a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiWjf6OjPGAAxV13TgGHcYPBV8QFnoECCYQAQ&amp;url=https%3A%2F%2Fwww.techtarget.com%2Fwhatis%2Fdefinition%2FIP-address-Internet-Protocol-Address&amp;usg=AOvVaw2ekx___J1_83_ftJqwOe3k&amp;opi=89978449">IP</a> (Internet Protocol) address is a unique address that identifies a device a device on the Internet. It is a set of rules assigned to how data will be sent over the internet.</p>
<h3 id="heading-6-data-link-layer"><strong>6. DATA LINK LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/3TLHavXiotb9ayyZFKECf3/9456d1c431cd71ceea7f4b407f076f11/data_link_layer_osi_model.png" alt /></p>
<p>Data Link Layer takes the data packet from the network layer and breaks them into smaller pieces called frames. This layer is also responsible for flow and error control.</p>
<h5 id="heading-functions-4"><strong>FUNCTIONS:</strong></h5>
<ul>
<li><p>FRAMING: Packets received from the network layer are called framing. A received data packet will be sent to the physical layer bit by bit. It also takes frames from the physical layer and sends them to the network layer.</p>
</li>
<li><p>ADDRESSING: The data link layer encapsulates the source and destination’s MAC physical address in the header of each frame to ensure node-to-node delivery</p>
</li>
<li><p>ERROR AND FLOW CONTROL: Corrupted data,s correction is the responsibility of the data link layer. The data link layer also synchronizes the sender's and receiver's speeds.</p>
</li>
</ul>
<h5 id="heading-protocols-used-5"><strong>PROTOCOLS USED:</strong></h5>
<p><a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjunP67jPGAAxVU1DgGHd0_Cs4QFnoECA4QAQ&amp;url=https%3A%2F%2Fwww.tutorialspoint.com%2Fnetwork-control-protocol-ncp&amp;usg=AOvVaw3BzsIkEV973R4yHxwnsk-B&amp;opi=89978449">NCP</a> (Network Control Protocol ) is a set of protocols forming a part of Point-to-Point Protocol (PPP), LCP (Link Control Protocol) is a part of PPP that operates in the data link layer.</p>
<h3 id="heading-7-physical-layer"><strong>7. PHYSICAL LAYER:</strong></h3>
<p><img src="https://cf-assets.www.cloudflare.com/slt3lc6tev37/1HQ1W5P4XAinIdM37DTu4U/900ccdceda346baf03ce8b9f977d2974/osi_model_physical_layer_1.png" alt /></p>
<p>This layer includes physical components that are necessary from data transfer, like cables and switches. This is the layer where data gets converted into bit streams (basically it is a string of 1s and 0s).</p>
<h5 id="heading-functions-5"><strong>FUNCTIONS:</strong></h5>
<ul>
<li><p>physical layer is the only layer in the OSI model that deals with physical connectivity and is responsible for establishing, maintaining and deactivating the physical connections of two different computing devices in a network.</p>
</li>
<li><p>The physical layer controls the flow of data rate.</p>
</li>
<li><p>It also deals with bit synchronization discussed above.</p>
</li>
</ul>
<hr />
<p><em>Since we have discussed all 7 layers of the OSI model in detail, now it is time to jump on to some real-life examples.</em></p>
<h3 id="heading-real-world-example-of-osi-model"><strong>REAL-WORLD EXAMPLE OF OSI MODEL:</strong></h3>
<p><strong>EMAIL WORKING</strong></p>
<p>Suppose you want an email to your friend. You open your browser and then the mail website from where you type your mail and tap on the send button. This mail then passes on to the <strong>application layer</strong> which will pick SMTP (used for emails) and pass the data to the <strong>presentation layer</strong>. The presentation layer will compress the data and then pass it to the <strong>session layer</strong>. In the session layer, the whole communication will start as it will start a session.</p>
<p>The data is then broken down into segments in the <strong>transport layer</strong>. Then those segments will be broken up into packets in the <strong>network layer</strong>, which will further be broken down into frames in the <strong>data link layer</strong>. The Data link layer then delivers those frames to the <strong>physical layer</strong> where they get converted into bit streams of 1s and 0s and sent through a physical medium such as cable.</p>
<p>Now, once your friend's system receives the bit stream through the physical layer (Wi-Fi etc.), the bit stream will flow through the same series but in the opposite direction.</p>
<p>The physical layer will convert the bit stream into frames and pass it to the data link layer. The data link layer then reassembles the frames converts them to packets and sends them to the network layer. Then the network layer will convert the packets to segments and the transport layer will reassemble the segments into data.</p>
<p>The data will then flow into the receiver's session layer, which will pass the data along to the presentation layer and then end the communication session. The presentation layer will then remove the compression and pass the raw data up to the application layer. The application layer will then feed the human-readable data along to your friend's email software, which will allow him to read your email on her laptop screen.</p>
<blockquote>
<h2 id="heading-thanks-for-reading"><strong>Thanks for reading !!</strong></h2>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Instant Knowledge #1 OOP]]></title><description><![CDATA[Encapsulation means wrapping up data and information under a single unit. It includes data, and functions which can affect the class. In Colleges, there…]]></description><link>https://cbum-dev.hashnode.dev/instant-knowledge-1-oop</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/instant-knowledge-1-oop</guid><category><![CDATA[oop]]></category><category><![CDATA[classes]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Tue, 04 Jul 2023 20:45:24 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-oopobject-oriented-programmings"><strong>OOP(Object Oriented Programming)'s</strong></h1>
<h2 id="heading-encapsulation"><strong>Encapsulation:</strong></h2>
<p>Encapsulation means wrapping up data and information under a single unit. It includes data, and functions which can affect the class.</p>
<h3 id="heading-example-of-encapsulation"><strong>Example of encapsulation :</strong></h3>
<p>In Colleges, there are different sections or departments which keep records of students in their respective departments. Like IT and Electrical department. Now if Someone from the IT department wants to get information about some students then he/she cannot directly access the data.</p>
<p>To do this he/she can ask the head of the department to provide the necessary information regarding the student. So here we can consider the whole college as a class and different departments as the data encapsulated inside the college class.</p>
<h2 id="heading-abstraction"><strong>Abstraction:</strong></h2>
<p>Abstraction means providing only the information which we want to make public, the rest of the data is private and not easily accessible. This helps in many scenarios where we don't want to show the internal working of something and want to hide it.</p>
<p>The data which is hidden may or may not be that private for example:</p>
<h3 id="heading-example-of-abstraction"><strong>Example of abstraction :</strong></h3>
<p>While driving a car, we use an accelerator to increase the speed of the car, but we don't want to know how it's working or how it is increasing the speed of our car.</p>
<p>Another example would be, When including header files in C++ like &lt;stdio.h&gt;. In this header file, <em>printf</em> function is there which prints the data which is present inside the parenthesis. We only want to use this function ignoring how it is working internally.</p>
<p>This is an abstraction in the real world.</p>
<h2 id="heading-polymorphism"><strong>Polymorphism:</strong></h2>
<p>Polymorphism means having many forms. It helps in code re-usability as a single function can be used in many other classes or within the same class. It allows to write code that can along multiple objects.</p>
<h3 id="heading-example-of-polymorphism"><strong>Example of polymorphism :</strong></h3>
<p>Suppose we want to print the area of a circle and rectangle. So we can create a superclass and define there a function with a name area and can reuse it in a rectangle as well as a circle.</p>
<h2 id="heading-inheritance"><strong>Inheritance:</strong></h2>
<p>The ability of a class to derive properties of some other class. Here a parent class is there which shares some of its properties with its child classes. It helps in code reusability, which means less code and more functionality.</p>
<h3 id="heading-example-of-inheritance"><strong>Example of inheritance :</strong></h3>
<p>Suppose there is a human class and some other classes such as male and female class. Now male and female classes can inherit all the properties present inside the human class.</p>
<p>So here Human class is the parent class which shares its properties and functionality with the male and female classes.</p>
]]></content:encoded></item><item><title><![CDATA[Your Friendly Neighbourhood Recursion.]]></title><description><![CDATA[To learn about Recursion let's first recall what is a function. Python function is created using the def keyword. For example: Now instead of calling the…]]></description><link>https://cbum-dev.hashnode.dev/your-friendly-neighbourhood-recursion</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/your-friendly-neighbourhood-recursion</guid><category><![CDATA[WeMakeDevs]]></category><category><![CDATA[Python]]></category><category><![CDATA[Recursion]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Fri, 31 Mar 2023 17:58:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1680285226507/2748a9bb-eb0f-44dc-b015-b0d50d8b96af.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-your-friendly-neighborhood-recursion">Your Friendly Neighborhood Recursion.</h1>
<h2 id="heading-what-is-recursion"><strong>What is Recursion?</strong></h2>
<p>To learn about <em>Recursion</em> let's first recall what is a function.</p>
<p>Python function is created using the def keyword. For example:</p>
<pre><code class="lang-plaintext">def func():
    print("hello world.")
func()      #function call
</code></pre>
<pre><code class="lang-plaintext">def func():
    print("Hello world.")
func()      #printing hello world 3 times
func()
func()
</code></pre>
<p>Now instead of calling the function every time we can make our job a little bit easier by using Recursion. So,</p>
<p><em>Recursion is a function that calls itself.</em> Thats it!!</p>
<p>For ex. printing the first 5 natural numbers</p>
<pre><code class="lang-plaintext">def number(n):
    if n==6:
        return
    print(n)
    number(n+1)
number(1)
</code></pre>
<h2 id="heading-when-to-use-recursion"><strong>When to Use Recursion</strong></h2>
<p>Iterative code becomes a little bit tricky when solving complex problems. To make yourself good at programming try both iterative as well as recursive solutions. Recursion thus helps to tackle some complex problems with ease and hence convert the problem into iteration afterwards.</p>
<p>However, recursion is not the best way to solve a particular problem because:</p>
<ol>
<li><p>They are a little slower than iterations because of function calls.</p>
</li>
<li><p>If the stack limit is too restrictive, iteration will be preferred over recursion.</p>
</li>
<li><p>They are hard to debug</p>
</li>
</ol>
<h2 id="heading-how-to-implement-recursion-effectively"><strong>How to Implement Recursion Effectively?</strong></h2>
<h4 id="heading-try-to-break-the-problem-into-a-simpler-set-of-equations">TRY TO BREAK THE PROBLEM INTO A SIMPLER SET OF EQUATIONS:</h4>
<p>Try to make the problem simpler by making simple calculations and making equations out of it. for example, to print the Fibonacci numbers we add the two previous numbers so by this</p>
<p>$$0+1=1, 1+1=2, 2+1=3, 3+2=5, 5+3=8,$$</p><p>So the seventh Fibonacci number is 8 That is the sum of 5 and 3.</p>
<p>To make a simple equation in</p>
<pre><code class="lang-plaintext">Fib(n)=Fib(n-1)+Fib(n-2)
</code></pre>
<p>So recursive code for the Fibonacci number is</p>
<pre><code class="lang-plaintext">def fib(n):
    if n&lt;=2:
        return n #if its less than 2 return the number
    return fib(n-1)+fib(n-2)
print(fib(5)) #output is 8
</code></pre>
<h4 id="heading-base-case">BASE CASE:</h4>
<p>The base case is a condition to stop the recursion otherwise the recursion will keep going on.</p>
<p>For example, to print the first 5 natural numbers in the example above, we made a condition" <strong>if n==6:</strong>" this made the recursion stop and we got our desired output.</p>
<p>In another new example: Suppose we want to produce the product of the first 10 natural numbers</p>
<pre><code class="lang-plaintext">def recursion(n):
    if n&lt;0 or n==1: #this is our base case 
        return 1
    else:
        return n*recursion(n-1)
print(recursion(10))
</code></pre>
<h4 id="heading-recursion-tree">RECURSION TREE:</h4>
<p>A recursion tree is a visualisation of what happens when recurrence is iterated.</p>
<p>For example the picture below of how Fibonacci problem tree looks like.</p>
<p><img src="https://imgs.search.brave.com/1v1nmaLV3qUxXrJkg8dYaO_Tg6JClz4trXZIooHJf4s/rs:fit:768:461:1/g:ce/aHR0cHM6Ly9ob2x5/Y29kZXJzLmNvbS9j/b250ZW50L2ltYWdl/cy93b3JkcHJlc3Mv/MjAyMC8wNC9maWJv/bmFjY2ktc2VxdWVu/Y2UtcmVjdXJzaW9u/LXRyZWUtNzY4eDQ2/MS5wbmc" alt="Fibonacci Sequence Algorithm: Recursion and Dynamic Programming" /></p>
<h2 id="heading-some-basic-questions-on-recursion-ltgt"><strong>Some basic questions on recursion. [&lt;/&gt;]</strong></h2>
<ol>
<li><p>Factorial of a number.</p>
<pre><code class="lang-plaintext"> def recursive_factorial(n):
    if n == 1:   #base case 
        return n #to stop n from getting 0 
    else:
        return n*recursive_factorial(n-1)
</code></pre>
</li>
<li><p>The sum of first n natural numbers</p>
<pre><code class="lang-plaintext"> def sum_n(n):
     if n== 0:
         return 0
     else:
         return n + sum_n(n-1)
 print(sum_n(3))
</code></pre>
</li>
<li><p>Multiple of 3 (Table of 3).</p>
<pre><code class="lang-plaintext"> def mult3(n):
     if n == 1:
         return 3
     else:
         return mult3(n-1) + 3
 ​
 for i in range(1,11):
         print(mult3(i))
</code></pre>
</li>
</ol>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>So this article is just an introduction to recursion and not much about it. The main idea is to give a basic idea of recursion and how it works.</p>
]]></content:encoded></item><item><title><![CDATA[Array Question.]]></title><description><![CDATA[First we define two variables large and sec_large and assign values 0 to them. Next we iterate through the entire list and make sec_large to large and…]]></description><link>https://cbum-dev.hashnode.dev/array-question</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/array-question</guid><category><![CDATA[Python]]></category><category><![CDATA[array]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Sat, 25 Feb 2023 09:02:43 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-q-finding-second-largest-element-in-the-arraypython">Q : Finding second largest element in the array(PYTHON):</h1>
<h2 id="heading-approach-1"><strong>Approach 1:</strong></h2>
<p>First we define two variables large and sec_large and assign values 0 to them.</p>
<p>Next we iterate through the entire list and make sec_large to large and large to a number greater than large in the list .</p>
<pre><code class="lang-plaintext">def Second_largest(list):
    largest = 0
    sec_largest = 0
    for item in list:
        if largest &lt; item:
            sec_largest = largest
            largest = item
    return sec_largest
print(Second_largest([10,20,30,40,60]))
</code></pre>
<h2 id="heading-approach-2"><strong>Approach 2:</strong></h2>
<p>First we sort the array in decsending order ,then return the second last element which is not equal to last.</p>
<pre><code class="lang-plaintext">def sec_large(arr):
    if len(arr)&lt;2: 
        return "No Second Element Exist."
    else:
        arr.sort() #sorting the array in descending order 
        for index in range(len(arr)-2,-1,-1): #iterating from second last to first element
            if arr[index] != arr[len(arr)-1]: #checking which element is not equal to last
                return arr[index]
        else:
            return "No Second Element Exist." 
print(sec_large([2,5,3,6,6]))
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Leap Year Code.]]></title><description><![CDATA[An extra day is added to february after every 4 years and the year is callled a leap year for ex.2016,2000,2020 etc.]]></description><link>https://cbum-dev.hashnode.dev/leap-year-code</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/leap-year-code</guid><category><![CDATA[Python]]></category><category><![CDATA[#codenewbies]]></category><category><![CDATA[leap_year]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Tue, 06 Sep 2022 08:16:27 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-leap-year-code-python">LEAP YEAR CODE (PYTHON).</h1>
<h2 id="heading-what-is-leap-year">What is Leap Year?</h2>
<p>An extra day is added to february after every 4 years and the year is callled a leap year for ex.2016,2000,2020 etc.</p>
<h2 id="heading-conditions-for-a-leap-year">Conditions for a leap year.</h2>
<ul>
<li>The year can be evenly divided by 4, is a leap year, unless:<ul>
<li>The year can be evenly divided by 100, it is NOT a leap year, unless:<ul>
<li>The year is also evenly divisible by 400. Then it is a leap year.</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="heading-code">Code:-</h2>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">is_leap</span>(<span class="hljs-params">year</span>):</span>
    leap = <span class="hljs-literal">False</span>
    <span class="hljs-keyword">if</span> year &gt; <span class="hljs-number">0</span>:<span class="hljs-comment">#year must be positve integer.</span>
        <span class="hljs-keyword">if</span> year % <span class="hljs-number">100</span>==<span class="hljs-number">0</span> <span class="hljs-keyword">and</span> year % <span class="hljs-number">400</span>==<span class="hljs-number">0</span>:<span class="hljs-comment">#acc to this rule(year that is divisble by 100 and                                                 400 both is a leap year.)</span>
            <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span>
        <span class="hljs-keyword">if</span> year %<span class="hljs-number">4</span> ==<span class="hljs-number">0</span> <span class="hljs-keyword">and</span> year%<span class="hljs-number">100</span>==<span class="hljs-number">0</span>:<span class="hljs-comment">#acc to this rule(yeaar that is divisible by 4 should                                         also be divisle by 100)</span>
            <span class="hljs-keyword">return</span> leap
        <span class="hljs-keyword">if</span> year%<span class="hljs-number">4</span>==<span class="hljs-number">0</span>:<span class="hljs-comment">#year is divisible by 4</span>
            <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span>
        <span class="hljs-keyword">else</span>:
            <span class="hljs-keyword">return</span> leap

year = int(input(<span class="hljs-string">"Enter year :-"</span>))
print(is_leap(year))
</code></pre>
<h2 id="heading-output">Output:-</h2>
<pre><code class="lang-python">Enter year :<span class="hljs-number">-2016</span>
<span class="hljs-literal">True</span>
Enter year :<span class="hljs-number">-1992</span>
<span class="hljs-literal">True</span>
Enter year :<span class="hljs-number">-2100</span>
<span class="hljs-literal">False</span>
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Exception handling in python.]]></title><description><![CDATA[There is another error names logical error in which error arrises due to wrong logic in code. These are most diificult error as python didnot return any…]]></description><link>https://cbum-dev.hashnode.dev/exception-handling-in-python</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/exception-handling-in-python</guid><category><![CDATA[Python]]></category><category><![CDATA[exceptionhandling]]></category><category><![CDATA[newbie]]></category><category><![CDATA[4articles4weeks]]></category><category><![CDATA[week1]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Sat, 20 Aug 2022 18:11:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661018918382/YT0qqZXqZ.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-exceptional-handling-in-python">EXCEPTIONAL HANDLING IN PYTHON.</h1>
<h2 id="heading-what-are-errors-in-python">What are errors in python?</h2>
<h3 id="heading-syntax-errors-these-errors-are-generated-by-wrong-syntax-in-python-for-example">Syntax errors : These errors are generated by wrong syntax in python . for example</h3>
<pre><code class="lang-python"><span class="hljs-number">1</span>K = <span class="hljs-number">199</span>
print(<span class="hljs-number">1</span>K)

output:
    <span class="hljs-number">1</span>K = <span class="hljs-number">199</span>
     ^
SyntaxError: invalid syntax
</code></pre>
<p>There is another error names logical error in which error arrises due to wrong logic in code. These are most diificult error as python didnot return any error and coder may find difficulty in finding the error.</p>
<h2 id="heading-what-are-exceptions">What are exceptions?</h2>
<p>Exceptions arrises when your code is syntactcally correct but the code result an error. This willresult in breaking the flow of program.</p>
<pre><code class="lang-python">x=<span class="hljs-number">100</span>
y=x/<span class="hljs-number">0</span>   <span class="hljs-comment">#this will return error as it is being divided by 0 .</span>
print(y)

output:
y=x/<span class="hljs-number">0</span>   <span class="hljs-comment">#this will return error as it is being divided by 0 .</span>
ZeroDivisionError: division by zero
</code></pre>
<p><em>To overcome the problems we use exceptional handling .</em></p>
<h2 id="heading-try-and-except-statement-in-python">Try and Except statement in python.</h2>
<p>These are used to catch any exception in the code. Expressions the can raise exceptions in the try clause are kept and user generated output will be given in place of error. for ex.</p>
<pre><code class="lang-python"><span class="hljs-keyword">try</span>:
    <span class="hljs-number">100</span>/<span class="hljs-number">0</span>
<span class="hljs-keyword">except</span>:
    print(<span class="hljs-string">"No error LOL"</span>)

output:
No error LOL
</code></pre>
<h2 id="heading-try-and-except-with-else-statement">Try and Except with Else statement.</h2>
<p>Try and except with else statement is used to handle those type of problems in which we need the code to execute to fullest .For ex:</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">div</span>(<span class="hljs-params">a,b</span>):</span>
    <span class="hljs-keyword">try</span>:
        c=a/b
    <span class="hljs-keyword">except</span>:
        print(<span class="hljs-string">"zero division error"</span>)
    <span class="hljs-keyword">else</span>:
        print(c)
div(<span class="hljs-number">2</span>,<span class="hljs-number">5</span>)
div(<span class="hljs-number">5</span>,<span class="hljs-number">0</span>)
div(<span class="hljs-number">5</span>,<span class="hljs-number">5</span>)

output:<span class="hljs-number">0.4</span>
       zero division error
       <span class="hljs-number">1.0</span>
</code></pre>
<h2 id="heading-finally-keyword">Finally Keyword.</h2>
<p>The statement or expression inside the finally keyword will always be executed. For ex.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">div</span>(<span class="hljs-params">a,b</span>):</span>
    <span class="hljs-keyword">try</span>:
        c=a/b
        print(c)
    <span class="hljs-keyword">except</span>:
        print(<span class="hljs-string">"zero division error"</span>)
    <span class="hljs-keyword">finally</span>:
        print(<span class="hljs-string">"I will execute everytime :-)"</span>)
div(<span class="hljs-number">4</span>,<span class="hljs-number">2</span>)
div(<span class="hljs-number">4</span>,<span class="hljs-number">0</span>)

output:
<span class="hljs-number">2.0</span>
I will execute everytime :-)
zero division error
I will execute everytime :-)
</code></pre>
<h2 id="heading-thankyou"><em>#THANKYOU</em></h2>
]]></content:encoded></item><item><title><![CDATA[Functions basics]]></title><description><![CDATA[To complete a repeated task and writing the same code again and again ,we use function to call the same code just by calling it . Function starts with def…]]></description><link>https://cbum-dev.hashnode.dev/functions-basics</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/functions-basics</guid><category><![CDATA[Python]]></category><category><![CDATA[functions]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[#codenewbies]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Sun, 07 Aug 2022 05:58:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1659851809994/dw09k3S3g.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-functions">F<em>UNCTIONS</em></h1>
<h2 id="heading-what-is-a-function-in-python">What is a function in python.</h2>
<p>To complete a repeated task and writing the same code again and again ,we use function to call the same code just by calling it .</p>
<p>Function starts with def keyword followed by function name and parameter in parenthesis.</p>
<p>def  ()</p>
<hr />
<h2 id="heading-creating-a-function">Creating a function.</h2>
<p>We can <strong>create</strong> a function by using def <a target="_blank" href="https://www.geeksforgeeks.org/python-keywords-and-identifiers/">keyword</a>.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">new_func</span>():</span>
    print(<span class="hljs-string">"This is new fucntion"</span>)
</code></pre>
<hr />
<h2 id="heading-calling-of-function">Calling of function</h2>
<p>After creating a function we can use it by <strong>calling</strong>.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">new_func</span>():</span>
    print(<span class="hljs-string">"calling of function."</span>)
new_func()

output:-calling of function.
</code></pre>
<h3 id="heading-calling-a-function-with-parameters">Calling a function with <code>parameters</code>.</h3>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">multiply</span>(<span class="hljs-params">x,y</span>):</span>
    z=x*y
    <span class="hljs-keyword">return</span> z
print(multiply(<span class="hljs-number">2</span>,<span class="hljs-number">4</span>))
print(multiply(<span class="hljs-number">4</span>,<span class="hljs-number">5</span>))

output:<span class="hljs-number">-8</span>
        <span class="hljs-number">20</span>
</code></pre>
<hr />
<h2 id="heading-arguments-in-functions">Arguments in functions.</h2>
<p>Arguments are the values passed inside a parameter.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">odd_even</span>(<span class="hljs-params">x</span>):</span>
    <span class="hljs-keyword">if</span> x%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>:
        print(<span class="hljs-string">"even"</span>)
    <span class="hljs-keyword">else</span>:
        print(<span class="hljs-string">"odd"</span>)
odd_even(<span class="hljs-number">9</span>)
odd_even(<span class="hljs-number">10</span>)

output:- odd
         even
</code></pre>
<hr />
<h2 id="heading-return-function">Return function .</h2>
<p>Return function is used to exit from function and return value assigned to it. A return can consists of expression ,string ,constant etc.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">ret</span>():</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">"return works like this ;)"</span>
print(ret())

output:- <span class="hljs-keyword">return</span> works like this;)*
</code></pre>
<hr />
<h2 id="heading-nested-function">Nested function</h2>
<p>We can use a function inside a function and can make code more advanced.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sum</span>():</span>
    x=<span class="hljs-number">4</span>+<span class="hljs-number">5</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">multiply</span>():</span><span class="hljs-comment">#nested function defined as multiply</span>
        z=x*<span class="hljs-number">5</span><span class="hljs-comment">#multiplying x with 5 </span>
        print(z)
    multiply()<span class="hljs-comment">#calling nested func inside main func.</span>
sum()<span class="hljs-comment">#calling main function.</span>

output:- <span class="hljs-number">45</span>
</code></pre>
<hr />
<h2 id="heading-some-examples">Some examples :</h2>
<h3 id="heading-1-ask-5-numbers-from-user-and-return-odd-or-even">1. Ask 5  numbers from user and return odd or even</h3>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">odd</span>(<span class="hljs-params">x</span>):</span>
    <span class="hljs-keyword">if</span> x%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-string">"even"</span>
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-string">"false"</span>
i=<span class="hljs-number">1</span>
<span class="hljs-keyword">while</span> i&lt;=<span class="hljs-number">5</span>:<span class="hljs-comment">#for five number of attempts</span>
    y=int(input(<span class="hljs-string">"enter x "</span>))
    print(odd(y))
    i+=<span class="hljs-number">1</span>

 output:-enter x <span class="hljs-number">12</span>
        even
        enter x <span class="hljs-number">23</span>
        false
        enter x <span class="hljs-number">34</span>
        even
        enter x <span class="hljs-number">45</span>
        false
        enter x <span class="hljs-number">56</span>
        even
</code></pre>
<h3 id="heading-2-to-find-maximum-of-two-numbers">2. To find maximum of two numbers.</h3>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">max</span>(<span class="hljs-params">x,y</span>):</span>
    <span class="hljs-keyword">if</span> x&gt;y:
        print(x,<span class="hljs-string">"is greater than "</span>,y)
    <span class="hljs-keyword">else</span>:
        print(y,<span class="hljs-string">"is greater than "</span>,x)
x=int(input(<span class="hljs-string">"Enter first number :-"</span>))
y=int(input(<span class="hljs-string">"Enter second number:-"</span>))
max(x,y)


output:Enter first number :<span class="hljs-number">-12</span>
       Enter second number:<span class="hljs-number">-322</span>
       <span class="hljs-number">322</span> <span class="hljs-keyword">is</span> greater than  <span class="hljs-number">12</span>
</code></pre>
<h3 id="heading-3-sum-of-all-numbers-in-a-list">3. Sum of all  numbers in a list.</h3>
<pre><code class="lang-python">list=[]
i=<span class="hljs-number">1</span>
<span class="hljs-keyword">while</span> i&lt;=<span class="hljs-number">5</span>:
    x=int(input(<span class="hljs-string">"Enter elements of list:-"</span>))
    list.append(x)
    i+=<span class="hljs-number">1</span>
print(<span class="hljs-string">"List you have entered :"</span>,list)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sum</span>():</span>
    add=<span class="hljs-number">0</span>
    <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
        add+=list[j]
    print(<span class="hljs-string">"Sum of all the elements of list is "</span>,add)
sum()

output:Enter elements of list:<span class="hljs-number">-12</span>
       Enter elements of list:<span class="hljs-number">-12</span>
       Enter elements of list:<span class="hljs-number">-12</span>
       Enter elements of list:<span class="hljs-number">-12</span>
       Enter elements of list:<span class="hljs-number">-12</span>
       List you have entered : [<span class="hljs-number">12</span>, <span class="hljs-number">12</span>, <span class="hljs-number">12</span>, <span class="hljs-number">12</span>, <span class="hljs-number">12</span>]
       Sum of all the elements of list <span class="hljs-keyword">is</span>  <span class="hljs-number">60</span>
</code></pre>
<h3 id="heading-similarily-you-can-create-as-many-programs-with-the-help-of-functions"><em>Similarily you can create as many programs with the help of functions.</em></h3>
<h1 id="heading-thank-you">ThanK You ;-)</h1>
]]></content:encoded></item><item><title><![CDATA[List comprehension.]]></title><description><![CDATA[LIST COMPREHENSION. What is list comprehension? List comprehension is an elegant way to create lists. A python list comprehension consists of expressions…]]></description><link>https://cbum-dev.hashnode.dev/list-comprehension</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/list-comprehension</guid><category><![CDATA[Python]]></category><category><![CDATA[list]]></category><category><![CDATA[#codenewbies]]></category><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Sat, 06 Aug 2022 17:13:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1659805917442/oZNlbHO7O.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-list-comprehension">LIST COMPREHENSION.</h1>
<h2 id="heading-what-is-list-comprehension">What is list comprehension?</h2>
<h3 id="heading-list-comprehension-is-an-elegant-way-to-create-lists-a-python-list-comprehension-consists-of-expressions-enclosed-by-square-brackets">List comprehension is an elegant way to create lists. A python list comprehension consists of expressions enclosed by square brackets.</h3>
<h4 id="heading-for-example">For example:</h4>
<pre><code class="lang-python"><span class="hljs-comment">#Normal way to create list.</span>
x=[]
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range (<span class="hljs-number">11</span>):<span class="hljs-comment">#creating a list from 0 to 10 </span>
    x.append(i)
print(x)

output:-  [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>]

<span class="hljs-comment">#List comprehension.</span>
x=[i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">11</span>)] <span class="hljs-comment">#creating a list from 0 to 10</span>
print(x)

output:-  [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>]
</code></pre>
<h2 id="heading-advantages-of-list-comprehension-over-normal-way">Advantages of list comprehension over normal way.</h2>
<h4 id="heading-1-more-time-efficient-and-space-efficient-than-loops">1. More time efficient and space efficient than loops.</h4>
<h4 id="heading-2-requires-fewer-lines-of-code">2. Requires fewer lines of code.</h4>
<h2 id="heading-working-of-list-comprehension">Working of list comprehension.</h2>
<h3 id="heading-xexpression-to-get-displayed-for-loop-for-range-of-elements-conditions">x=[(expression to get displayed ) (for loop , for range of elements) (conditions)]</h3>
<h3 id="heading-for-example">For example:-</h3>
<pre><code class="lang-python">x=[i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">11</span>) <span class="hljs-keyword">if</span> i%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>]
<span class="hljs-comment">#expression followed by range and condition</span>
print(x)

output:-[<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>]
</code></pre>
<h2 id="heading-some-examples-of-comprehension">Some examples of comprehension.</h2>
<h3 id="heading-1-creating-a-list-of-even-numbers-from-0-to-100">1. Creating a list of even numbers from 0 to 100.</h3>
<pre><code class="lang-python">x=[i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">100</span>) <span class="hljs-keyword">if</span> i%<span class="hljs-number">2</span>==<span class="hljs-number">0</span> ] 
<span class="hljs-comment">#range of 100 numbers with condition.</span>
print(x)

output:-[<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>, <span class="hljs-number">12</span>, <span class="hljs-number">14</span>, <span class="hljs-number">16</span>, <span class="hljs-number">18</span>, <span class="hljs-number">20</span>, <span class="hljs-number">22</span>, <span class="hljs-number">24</span>, <span class="hljs-number">26</span>, <span class="hljs-number">28</span>, <span class="hljs-number">30</span>, <span class="hljs-number">32</span>, <span class="hljs-number">34</span>, <span class="hljs-number">36</span>, <span class="hljs-number">38</span>, <span class="hljs-number">40</span>, <span class="hljs-number">42</span>, <span class="hljs-number">44</span>, <span class="hljs-number">46</span>, <span class="hljs-number">48</span>, <span class="hljs-number">50</span>, <span class="hljs-number">52</span>, <span class="hljs-number">54</span>, <span class="hljs-number">56</span>, <span class="hljs-number">58</span>, <span class="hljs-number">60</span>, <span class="hljs-number">62</span>, <span class="hljs-number">64</span>, <span class="hljs-number">66</span>, <span class="hljs-number">68</span>, <span class="hljs-number">70</span>, <span class="hljs-number">72</span>, <span class="hljs-number">74</span>, <span class="hljs-number">76</span>, <span class="hljs-number">78</span>, <span class="hljs-number">80</span>, <span class="hljs-number">82</span>, <span class="hljs-number">84</span>, <span class="hljs-number">86</span>, <span class="hljs-number">88</span>, <span class="hljs-number">90</span>, <span class="hljs-number">92</span>, <span class="hljs-number">94</span>, <span class="hljs-number">96</span>, <span class="hljs-number">98</span>]
</code></pre>
<h3 id="heading-2-nested-list-comprehension">2. Nested list comprehension.</h3>
<pre><code class="lang-python"><span class="hljs-comment">#This is called matrix and a nested comprehension.</span>
x=[[i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">3</span>)] <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>)]
<span class="hljs-comment">#range from 1 to 3 and number of repetitions 5</span>
print(x)

output:-[[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]]
</code></pre>
<h3 id="heading-3-squares-of-10-numbers">3. Squares of 10 numbers.</h3>
<pre><code class="lang-python">x=[i**<span class="hljs-number">2</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">11</span>)]
print(x)

output:-[<span class="hljs-number">1</span>, <span class="hljs-number">4</span>, <span class="hljs-number">9</span>, <span class="hljs-number">16</span>, <span class="hljs-number">25</span>, <span class="hljs-number">36</span>, <span class="hljs-number">49</span>, <span class="hljs-number">64</span>, <span class="hljs-number">81</span>, <span class="hljs-number">100</span>]
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Learning Python: Lists And Tuples.]]></title><description><![CDATA[List is a collection of data enclosed by []. Lists are mutable , which means the values inside the list can be changed anytime . List may contain string…]]></description><link>https://cbum-dev.hashnode.dev/learning-python-lists-and-tuples</link><guid isPermaLink="true">https://cbum-dev.hashnode.dev/learning-python-lists-and-tuples</guid><dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator><pubDate>Wed, 29 Jun 2022 18:20:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1656526764134/SZOhbNrpx.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-list">LIST</h1>
<h2 id="heading-what-is-list">What is list?</h2>
<p>List is a collection of data enclosed by []. Lists are mutable , which means the values inside the list can be changed anytime . List may contain string , integers ,a list inside a list or all of these in a single list itself.</p>
<p>A list can be created by simply putting values enclosed by [].</p>
<h2 id="heading-list-operations">List operations.</h2>
<h3 id="heading-1-length-of-a-list">1. Length of a list .</h3>
<p>To know the length of  list we use len() function. for ex.</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]
len(list) <span class="hljs-comment">#this will return 3</span>
</code></pre>
<h3 id="heading-2-indexing-in-list">2. Indexing in list.</h3>
<p>Elements of a list are arranged in a definite sequence ,called indexes . The first element is treated as (0)th index and last element is treated as (n-1)th index . for ex.</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">10</span>,<span class="hljs-number">20</span>,<span class="hljs-number">30</span>]
<span class="hljs-comment">#index of 10 is 0</span>
<span class="hljs-comment">#index of 20 is 1 </span>
<span class="hljs-comment">#index of 30 is 2</span>
</code></pre>
<h3 id="heading-3-slicing-in-ist">3. Slicing in ist.</h3>
<p>Slicing is sublist of a list. for ex.</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>]
list2=list1[<span class="hljs-number">1</span>:<span class="hljs-number">3</span>] <span class="hljs-comment">#this will extract a new list from index 1 to 3 .</span>
print(list2) <span class="hljs-comment">#output will be [2,3] as 3 gets excluded.</span>
</code></pre>
<h3 id="heading-4-adding-and-removing-elements-in-a-list">4. Adding and removing elements in a list.</h3>
<p>a. We can add an element in a list by using append() fucntion .</p>
<p>Append fuction will add an element to a list at the end .Append will only insert 1 element ,to add multiple elements we use insert() fuction.</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]
list1.append(<span class="hljs-number">4</span>)
<span class="hljs-comment">#this will add 4 at the end of list1  </span>
<span class="hljs-comment">#new list is [1,2,3,4]</span>
</code></pre>
<p>b. insert fuction</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]
list1.insert(<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>)
<span class="hljs-comment">#this will add 4,5,6 at the end of list1</span>
<span class="hljs-comment">#new list is [1,2,3,4,5,6]</span>
</code></pre>
<p>c. To merge two lists extend fucion is used. for ex,</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>]
list2=[<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]
list1.extend(list2)
<span class="hljs-comment">#this will merge the two lists and return [1,2,3,4,5,6]</span>
</code></pre>
<p>d.To remove an element in a list we use pop() fuction.</p>
<p>pop function will remove the indexed element and return it to the user. for ex.</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>]
list1.pop(<span class="hljs-number">3</span>) <span class="hljs-comment">#this will remove the 4th elements i.e 4 from the list as at 3rd index 4 is there.</span>
</code></pre>
<p>e. To remove elements we use remove function. remove fuction will remove the element given by the user . for ex.</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>]
list1.remove(<span class="hljs-number">5</span>)
<span class="hljs-comment">#this will remove 5 from the list</span>
</code></pre>
<p>f. Sorting :- sort() fucntion will arrange the elements of the list in ascending order .</p>
<pre><code class="lang-python">list1=[<span class="hljs-number">4</span>,<span class="hljs-number">3</span>,<span class="hljs-number">2</span>,<span class="hljs-number">6</span>,<span class="hljs-number">1</span>]
list1.sort()
<span class="hljs-comment">#this will sort the list and return [1,2,3,4,6]</span>
</code></pre>
<h3 id="heading-here-is-code-having-multiple-operations-of-a-list"><em>HERE IS CODE HAVING MULTIPLE OPERATIONS OF A LIST</em>.</h3>
<pre><code class="lang-python">x=<span class="hljs-string">'hello'</span>
list1=[<span class="hljs-number">20</span>,<span class="hljs-number">12</span>,<span class="hljs-number">32</span>,<span class="hljs-number">11</span>,<span class="hljs-number">65</span>,<span class="hljs-number">32</span>]
print(list(x)) <span class="hljs-comment">#create a list of alphabets 'hello'</span>
print(list1.append(<span class="hljs-number">13</span>)) <span class="hljs-comment">#this will add 13 to the list.</span>
list2=list1[<span class="hljs-number">2</span>:<span class="hljs-number">5</span>] <span class="hljs-comment">#slicing</span>
print(list2) <span class="hljs-comment">#this will create a new list having 3 elements only.</span>
print(list1.sort()) <span class="hljs-comment"># this will sort the list in ascending order.</span>
print(list1.reverse()) <span class="hljs-comment"># this will reverse the list.</span>
print(list1.extend(list2)) <span class="hljs-comment">#this will add all the elements of list2 in list1.</span>
x=list1.pop() <span class="hljs-comment"># pop fucntion</span>
print(x) <span class="hljs-comment">#poped item</span>
print(list1.remove(<span class="hljs-number">12</span>)) <span class="hljs-comment"># this will remove 12 from the list.</span>
<span class="hljs-comment">#end</span>
</code></pre>
<h1 id="heading-tuples">TUPLES</h1>
<h2 id="heading-what-is-a-tuple">What is a tuple?</h2>
<p>Tuple is  collection a data like list . The values stored in a tuple can be of any data type seperated by commas . Tuples are immutable means the values can not be changed like in list.</p>
<p>A tuple can be created by simply adding values enclosed by () seperated by commas .</p>
<h2 id="heading-tuple-operations">Tuple operations.</h2>
<h3 id="heading-1-creating-a-tuple">1.  creating a tuple.</h3>
<pre><code class="lang-python">x=<span class="hljs-string">'hello'</span>
tuple1=tuple(x)
print(tuple1)
<span class="hljs-comment">#this will create a tuple for the word hello where each alphabet gets seperated by a comma.</span>
</code></pre>
<h3 id="heading-2-length-of-tuple">2. Length of tuple .</h3>
<p>Len function is used to find the length of a tuple. for ex.</p>
<pre><code class="lang-python">tuple1=(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">34</span>,<span class="hljs-number">4</span>)
len(tuple1) <span class="hljs-comment">#this willl return 4 (the length of tuple1.)</span>
</code></pre>
<h3 id="heading-3-indexing-in-tuple">3. Indexing in tuple.</h3>
<p>Indexing in tuple is same as of list .</p>
<pre><code class="lang-python">tuple1=(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>)
print(tuple1[<span class="hljs-number">2</span>])
<span class="hljs-comment">#this will return 3 ,as 3 is in second index.</span>
</code></pre>
<h3 id="heading-4-concatenation-in-tuples">4. Concatenation in tuples.</h3>
<p>Two tuples can be concatenated by simply using + between them. for ex.</p>
<pre><code class="lang-python">tuple1=(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>)
tuple2=(<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>)
tuple3=tuple1+tuple2
print(tuple3)<span class="hljs-comment">#merged tuple.</span>
</code></pre>
<h3 id="heading-5-deleting-a-tuple">5. Deleting a tuple.</h3>
<p>A tuple can be deleted by using del() function</p>
<pre><code class="lang-python">tuple1=(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>)
<span class="hljs-keyword">del</span> tuple1 <span class="hljs-comment"># tuple deleted</span>
print(tuple1) <span class="hljs-comment">#this will give error as tuple1 is already deleted.</span>
</code></pre>
<h3 id="heading-6-maximum-and-minumum-value-in-a-tuple">6. Maximum and minumum value in a tuple.</h3>
<p>By using min and max fuction we can find the minimum and maximum value in a tuple.</p>
<p>for ex.</p>
<pre><code class="lang-python">tuple1=(<span class="hljs-number">2</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">3</span>)
tuple1.max() <span class="hljs-comment"># this will return 6</span>
tuple2.max() <span class="hljs-comment"># this will return 2</span>
</code></pre>
<h2 id="heading-here-is-code-having-multiple-operations-of-a-tuple"><em>HERE IS CODE HAVING MULTIPLE OPERATIONS OF A TUPLE.</em></h2>
<pre><code class="lang-python">x=<span class="hljs-string">'hello'</span>
tuple1=(<span class="hljs-number">20</span>,<span class="hljs-number">12</span>,<span class="hljs-number">32</span>,<span class="hljs-number">11</span>,<span class="hljs-number">65</span>,<span class="hljs-number">32</span>)
print(tuple1(x)) <span class="hljs-comment">#create a tuple of alphabets 'hello'</span>
tuple2=tuple1[<span class="hljs-number">2</span>:<span class="hljs-number">5</span>] <span class="hljs-comment">#slicing</span>
print(tuple2) <span class="hljs-comment">#this will create a new tuple having 3 elements only.</span>
print(tuple1[<span class="hljs-number">0</span>])<span class="hljs-comment"># this will return value at index 0.</span>
print(tuple1.max())
<span class="hljs-keyword">del</span> tuple1 <span class="hljs-comment">#this will delete tuple.</span>
<span class="hljs-comment">#end</span>
</code></pre>
<h1 id="heading-difference-between-a-list-and-a-tuple"><em>DIFFERENCE BETWEEN A LIST AND A TUPLE.</em></h1>
<div class="hn-table">
<table>
<thead>
<tr>
<td>s.no</td><td>DIFFERENCES</td></tr>
</thead>
<tbody>
<tr>
<td>1.</td><td>Lists are mutable whereas tuples are immutable .So we can use them according to our preferences. We can use tuple for data that need not to be changed later .</td></tr>
<tr>
<td>2.</td><td>Operations in tuple is bit faster than lists.</td></tr>
<tr>
<td>3.</td><td>Lists provide more fuctions in comparison to tuple.</td></tr>
</tbody>
</table>
</div>]]></content:encoded></item></channel></rss>