<?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 Mashapathri Anjali on Medium]]></title>
        <description><![CDATA[Stories by Mashapathri Anjali on Medium]]></description>
        <link>https://medium.com/@mashapathrianjali03?source=rss-90d2431a95c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*XHhqQX71sCMHX64-</url>
            <title>Stories by Mashapathri Anjali on Medium</title>
            <link>https://medium.com/@mashapathrianjali03?source=rss-90d2431a95c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:38:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mashapathrianjali03/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[Set and Dictionary]]></title>
            <link>https://medium.com/@mashapathrianjali03/set-and-dictionary-34f82c488a8b?source=rss-90d2431a95c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/34f82c488a8b</guid>
            <dc:creator><![CDATA[Mashapathri Anjali]]></dc:creator>
            <pubDate>Tue, 21 Jul 2026 02:33:43 GMT</pubDate>
            <atom:updated>2026-07-21T02:33:43.033Z</atom:updated>
            <content:encoded><![CDATA[<h4>SET</h4><p>A Set is a collection data structure used to store multiple values in a single variable.</p><h4>Ways to Create a Set</h4><p>There are 2 ways to create a set.</p><ol><li><strong>Using Curly Braces { }</strong></li></ol><p>set_name = {value1, value2, value3…..}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*pj7oVBxl9Zp1ZHSMBjYo9A.png" /><figcaption>Example</figcaption></figure><p><strong>2) Using the set() Constructor</strong></p><p>The set() constructor converts another iterable into a set.</p><p><strong>Syntax</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*MbOzhPcSlt32LeABJE3FyA.png" /><figcaption>example 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*UlObk6-gsZX6QQBAKBaw4Q.png" /><figcaption>example 2</figcaption></figure><p><strong>Why can’t we store a list inside a set?</strong></p><p>A list is mutable (unhashable).</p><p>A set can store only hashable (immutable) objects.</p><p>Because lists can be modified, Python does not allow them inside a set.</p><h4>Properties of Set</h4><ol><li><strong>Sequential Data</strong></li></ol><p>A set stores multiple values in a single variable.</p><p><strong>2. Unordered</strong></p><p>A set does not maintain insertion order. This means we do not know the exact position of the elements.</p><p>Every time you run the program, the order may be different.</p><p>Therefore, sets are unordered.</p><p><strong>3. No Indexing or Slicing</strong></p><p>Elements in a set do not have index values.</p><p>Since there is no order, sets do not support indexing or slicing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*8B0b8yU2hnpztUeur_zWsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*FKeNoShQL0zI0EYqnnMECA.png" /></figure><p><strong>4. Does Not Support Duplicates</strong></p><p>Duplicate values are automatically removed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*vceCrTctt4wgws-DqA99Nw.png" /></figure><p>Only one copy is stored.</p><p><strong>Boolean and Integer Special Case</strong></p><p>Python treats True as 1 and False as 0.</p><p>Therefore, they are considered duplicates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*RC8oBfm8etkoR8Ux-n4hRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*C7mPaxl5PbIBI5JwAX1H7A.png" /></figure><h4><strong>Sets are Partially Mutable</strong></h4><p>We cannot replace an existing element directly.</p><p>We can add new elements.</p><p>We can remove existing elements.</p><p>That is why a set is called partially mutable.</p><h4><strong>Adding Elements</strong></h4><p><strong>1. add( )</strong></p><p>Used to add only one element to a set.</p><p><strong>Syntax:</strong></p><p>set_name.add(element)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*LAyRA1fS3gFUTjb82wfYVQ.png" /></figure><p><strong>2. update( )</strong></p><p>Used to add multiple elements at once.</p><p><strong>Syntax:</strong></p><p>set_name.update(iterable)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*iM3Rls5h0r4uQJD_Yb9QDQ.png" /></figure><h4>Removing Elements</h4><ol><li>remove( )</li></ol><p>Removes one specified element.</p><p><strong>Syntax:</strong></p><p>set_name.remove(element)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*06NKvSj5Rl9MOEdnjW46hQ.png" /></figure><p>If the element is not present, it raises an error.</p><p><strong>2. discard( )</strong></p><p>Also removes one specified element.</p><p>If the element is not present, no error occurs.</p><p><strong>Syntax:</strong></p><p>set_name.discard(element)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*zqxPiIAUXrcwYuPIW6clKw.png" /></figure><p>If the element does not exist there will be no error.</p><p><strong>3. clear( )</strong></p><p>Removes all elements and returns an empty set.</p><p><strong>Syntax:</strong></p><p>set_name.clear()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*f1FeuiCE6IBAdX6A66vEHg.png" /></figure><p><strong>4. pop( )</strong></p><p>Removes one random element from the set.</p><p><strong>Syntax:</strong></p><p>set_name.pop()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*rkLjv3gbso9ZVSuwUpDUYQ.png" /></figure><h4>Concatenation</h4><p>String:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*UQgY0m6-3vX-Qa3SEylaYA.png" /></figure><p>List:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*oFEHcU8kbmhw4Rn9p6BEig.png" /></figure><p>Tuple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*FLX_ZVhWU-gPNuzYtxtHyQ.png" /></figure><p>Dictionary and Set <strong>do not support concatenation using +.</strong></p><p>Instead, sets use special methods like:</p><p>union()</p><p>intersection()</p><p>difference()</p><p>symmetric_difference()</p><h4>Set Operations</h4><p><strong>1. union()</strong></p><p>Combines all elements from both sets.</p><p>Duplicate values appear only once.</p><p><strong>Syntax: </strong>set1.union(set2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*aWhO865jS94-oK6vM6I92w.png" /></figure><p>A <strong>new set</strong> is created.</p><p><strong>2. update()</strong></p><p>Performs union but changes the original set.</p><p><strong>Example</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*aWhO865jS94-oK6vM6I92w.png" /></figure><p>No new set is created.</p><p><strong>3. intersection()</strong></p><p>Returns only the common elements.</p><p><strong>Syntax: </strong>set1.intersection(set2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*4estB7WmHVzgJuKuYM8Y-A.png" /></figure><p><strong>4. difference()</strong></p><p>Returns elements that are present in the first set but not in the second set.</p><p><strong>Syntax: </strong>set1.difference(set2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*uROXbdE_mudwSxpiUeqqwg.png" /></figure><p><strong>5. Symmetric_difference()</strong></p><p>Removes common elements and keeps only uncommon elements.</p><p><strong>Syntax:</strong> set1.symmetric_difference(set2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*UUIKBS-i_D1wlMKFREwyUQ.png" /></figure><h3>Dictionary</h3><p>A Dictionary is a collection data structure used to store data in the form of key : value pairs.</p><p>Each key is unique and is used to access its corresponding value.</p><h4>Ways to Create a Dictionary</h4><p>There are 2 ways to create a dictionary.</p><h4><strong>1. Using Curly Braces { }</strong></h4><p><strong>Syntax:</strong></p><p>dict_name = {key1: value1,key2: value2,key3: value3}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*nZblKiK1MFqUpPB5ZotO1Q.png" /><figcaption>Example</figcaption></figure><h4>2. Using the dict() constructor</h4><p>The dict() constructor follows the naming convention.</p><p><strong>Syntax:</strong> dict_name = dict(key=value)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*3sHODw613Mn_QVzLe7d9Yg.png" /><figcaption>Example</figcaption></figure><p>Keys are usually created using int or str.</p><p>Values can be of any data type.</p><h4>Properties of Dictionary</h4><h4>1. Sequential Data</h4><p>A dictionary stores multiple key : value pairs in a single variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*3sHODw613Mn_QVzLe7d9Yg.png" /></figure><h4>2. Ordered</h4><p>A dictionary maintains the insertion order of its elements.</p><h4>3. Keys Act as an Index</h4><p>Keys are used to access values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*7oeau85BDY2TADZm5BXsPw.png" /></figure><h4>4. Keys Do Not Allow Duplicates</h4><p>Duplicate keys are not allowed.</p><p>If the same key is written again, the latest value is stored.</p><p>Values can have duplicates.</p><h4>5. Dictionaries are Mutable</h4><p>We can:</p><p>Add new key:value pairs.</p><p>Replace existing values.</p><p>Delete key:value pairs.</p><h3>→ Replacing Values</h3><p>There are 2 methods to replace values.</p><h4>1. Using Indexing</h4><p>Dictionaries support indexing through keys.</p><p><strong>Syntax: </strong>dict_name[key] = new_value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*4bL3kyXWXj6LkrZzu-NGJg.png" /></figure><p>They do not support slicing.</p><h4>2. Using update()</h4><p>The update() method is used to replace one or more key:value pairs.</p><p>It can replace a single value or multiple values at a time.</p><p><strong>Syntax : </strong>dict_name.update({key:value})</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*myrHeva4KxXdjIOHlo-3yg.png" /></figure><h3>→ Adding Elements</h3><h4>1. Using Indexing</h4><p>If the key already exists, its value is replaced.</p><p>If the key does not exist, a new key:value pair is added.</p><p><strong>Syntax: </strong>dict_name[key] = value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*yN3uJZNgVr7VJSIJYBL_Bw.png" /></figure><h4>2. Using update()</h4><p>Adds one or more key:value pairs.</p><p><strong>Syntax:</strong> dict_name.update({key:value})</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*5OLCVqMT2O8FwOAsP9vDag.png" /></figure><h3>→ Deleting</h3><p>We cannot delete only values.</p><p>We delete keys, and the corresponding values are also removed automatically.</p><p>There are 4 methods.</p><h4>1. del</h4><p>Deletes a specific key and its value.</p><p><strong>Syntax: </strong>del dict_name[key]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*zjuzWk88-xYQr-TV0cPyww.png" /></figure><h4>2. pop()</h4><p>Removes the specified key and returns its value.</p><p><strong>Syntax : </strong>dict_name.pop(key)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*yUTWS5ztCscEbN5yskfZew.png" /></figure><h4>3. popitem()</h4><p>Removes the last inserted key:value pair.</p><p><strong>Syntax: </strong>dict_name.popitem()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*9ElE1N7xFX5OvSKDUquHVw.png" /></figure><h4>4. clear()</h4><p>Removes all key:value pairs and returns an empty dictionary.</p><p><strong>Syntax: </strong>dict_name.clear()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*qTrvweW3QXQnNIe9LIyjJw.png" /></figure><h3>→ Other Dictionary Methods</h3><h4>5. get()</h4><p>Used to access a value.</p><p>If the key is found, it returns its value.</p><p>If the key is not found, it returns None.</p><p>It does not raise an error.</p><p><strong>Syntax: </strong>dict_name.get(key)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*o0QpJSm3a7EAafzsfTk8_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*juefA7j0UdR9a_Vbq6hYrA.png" /><figcaption>if the key is not found, it does not raise error,returns none.</figcaption></figure><h4>6. copy()</h4><p>Creates a copy of the dictionary.</p><p><strong>Syntax: </strong>new_dict = dict_name.copy()</p><h4>7. keys()</h4><p>Returns all the keys of the dictionary.</p><p><strong>Syntax:</strong> dict_name.keys()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*DtroGwRC4tvbdZr8IDJY0g.png" /></figure><h4>8. values()</h4><p>Returns all the values of the dictionary.</p><p><strong>Syntax: </strong>dict_name.values()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*EmzRkTAdJIpR40k0b-hltw.png" /></figure><h4>9. items()</h4><p>Returns both keys and values together.</p><p><strong>Syntax: </strong>dict_name.items()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*HctiJ8RtMbXKs6QUMXIqkA.png" /></figure><h3>→ Nested Dictionary</h3><p>A nested dictionary is a dictionary inside another dictionary.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*0nd3FvrlTomhjmjW4Ugunw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34f82c488a8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[List and Tuple]]></title>
            <link>https://medium.com/@mashapathrianjali03/list-and-tuple-7feaa0e41093?source=rss-90d2431a95c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7feaa0e41093</guid>
            <dc:creator><![CDATA[Mashapathri Anjali]]></dc:creator>
            <pubDate>Mon, 20 Jul 2026 15:36:06 GMT</pubDate>
            <atom:updated>2026-07-20T15:37:23.076Z</atom:updated>
            <content:encoded><![CDATA[<p>List is a collection data structure</p><p>Lists are used to store multiple values in a single variable.</p><p>Lists are created using square brackets [].</p><h4><strong>Syntax:</strong></h4><ol><li>[e1, e2, e3, e4……en] → Representation of a list</li></ol><p>The elements inside a list can be same or it can be any data structure.</p><p>2. Lists are created using constructor called list constructor</p><p>→ list((e1, e2, e3, e4,….,en))</p><p>A list can store different types of data (integers, floats, strings, boolean).</p><p>A list can also be created as an empty list.</p><h4>Example:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*cID0BsqLWlwwNNVK.png" /></figure><h4><strong>Properties of a List:</strong></h4><ol><li>A list is a sequential data structure that can contain ’n’ number of elements arranged in sequential order.</li><li>All the elements inside a list are ordered.</li></ol><p>3. Every element inside a list has an address called an Index.</p><p>There are two types of indexes:</p><ul><li>Positive Index</li><li>Negative Index</li></ul><p>4. A list allows duplicate elements.</p><p>5. A list is mutable, which means that once it is created, we can add new data, replace existing data, and delete existing data.</p><h4>len( )</h4><p>len() is used to find the number of elements present in a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*1qbPRV4z7E6BChIRCS1JNw.png" /></figure><h4><strong>To prove that a list is sequential :</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*U-yzKD1hal4kqnXtK53csw.png" /></figure><ol><li>Every element inside a list has an index.</li></ol><p>2. Since every element has an index, the list is ordered.</p><p>3. Therefore, we can access a single element or a sequence of elements.</p><h4><strong>Indexing:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*x2JwHme_o9hp2hiEKn9Mng.png" /></figure><h4><strong>Slicing:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*FvFO_fKtrhMUAjqn6eVTYw.png" /></figure><p>A list supports Indexing and Slicing.</p><h4><strong><em>Replacing:</em></strong></h4><p>Replacing means changing an existing element with a new element.</p><p>To replace an element, first access it and then assign the new value.</p><h4><strong>Replacing One Element :</strong></h4><p>Replacing a single element can be done using Indexing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*3ZCXMNH1tFhf6QD0ks8SYQ.png" /></figure><h4><strong>Replacing Multiple Elements :</strong></h4><p>Replacing multiple elements in a sequence can be done using Slicing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*iciTz_9JJJXGy9im85DsDA.png" /></figure><p>Until we access an index, we cannot replace an element.</p><p>If we insert values at an index, the existing elements are pushed towards the right.</p><h3><strong>Adding:</strong></h3><p>Adding should be done without replacing existing elements.</p><p>The original data should not be affected.</p><p>We cannot use indexing or slicing for adding elements.</p><p>To add elements into a list we have some list methods</p><h4><strong>List Methods:</strong></h4><p>List methods are built-in functions that can be applied to a list.</p><h4><strong>1) insert(index, element)</strong></h4><p>insert() is used to add a single element at a specific position without replacing the existing element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*bXbkaCsl82j-iEUF41t1dw.png" /></figure><p>In the insert() method, we can use both positive and negative indexes.</p><p>It adds only one element at a time.</p><h4><strong>2) append(element)</strong></h4><p>append() is used to add a single element at the end of the list without replacing any existing element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*zg4u3VtYvp2vigFcV0Im0w.png" /></figure><h4><strong>3) extend(sequential data / iterable data)</strong></h4><p>extend() is used to add multiple elements to a list at a time.</p><p>The data passed must be a sequential (iterable) data type.</p><p>All the elements are added at the end of the list.</p><p>If a string is passed, each character is added separately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*Vl0StB_k61NDIAMDJXxNZg.png" /></figure><h3>Removing</h3><h4><strong>1. remove()</strong></h4><p>remove() is used to remove a single element at a time.</p><p>It removes the first occurrence of the specified element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*M90SVhVoPpqJnhG6WgWSYw.png" /></figure><h4><strong>2. pop(index)</strong></h4><p>pop() is used to remove a single element using its index.</p><p>The default index value is -1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*rsnoh2Yb7LBHeuyZVovnTA.png" /></figure><h4><strong>3. clear()</strong></h4><p>clear() removes all the elements from the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*XOPii0gfLO5UwkqK9HV88Q.png" /></figure><h4><strong>4. del</strong></h4><p>del is a keyword used to delete elements from a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*-_aA9UaPGRbMK425W8aa5w.png" /></figure><p>some of the other list methods are:</p><p><strong>5. count(element)</strong></p><p>count() is used to count the number of occurrences of an element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*pORe8f_zjFYAVKQZFCc_NA.png" /></figure><p><strong>6. index(element)</strong></p><p>index() is used to find the index of the first occurrence of an element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*7E17gEdcb_0G3i1VtpP9XA.png" /></figure><p><strong>7. sort()</strong></p><p>sort() is used to sort the elements in a list in ascending order.</p><p>The list should contain elements of the same data type, such as int,float,bool or str</p><p>By default, the elements are sorted in ascending order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*Db5JpT37jikhIu88vPKPGQ.png" /><figcaption>sorting in ascending order</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*FpZyGBRqZJgbsJCDwTTsdg.png" /><figcaption>Sorting in Descending Order</figcaption></figure><h3>Tuple:</h3><p>A tuple is a collection data type used to store ’n’ number of data values.</p><h4><strong>Syntax</strong></h4><p><strong>a) (e1, e2, e3, ……, en)</strong></p><p>Elements can be of the same or different data types.</p><p>This is the representation of a tuple.</p><p>Elements can be int,float,str,bool,list.</p><h4><strong>b) Tuple Constructor</strong></h4><p>tuple((e1, e2, e3, ……, en))</p><p>A tuple can be created with one element or ’n’ number of elements.</p><p>A tuple can also be created as an empty tuple.</p><p>To create a tuple with a single element, a comma <strong>(,)</strong> is mandatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*CvMDbOnvQsXPEHRJY3iTVg.png" /></figure><h4><strong>Properties of Tuple :</strong></h4><p>1. A tuple is a sequential data structure that can contain ’n’ number of elements arranged in sequential order.</p><p>2. All the elements inside a tuple are ordered.</p><p>3. Every element inside a tuple has an address called an Index.</p><p>There are two types of indexes:</p><p>Positive Index</p><p>Negative Index</p><p>4. Tuple allows duplicate elements.</p><p>5. A tuple is immutable.</p><p>Once a tuple is created, we cannot add, replace, or delete its elements.</p><h4><strong>len()</strong></h4><p>len() is used to find the number of elements present in a tuple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*2EmThNt0DH3nAGVemkRKHA.png" /></figure><h4><strong>Looping Through a Tuple :</strong></h4><p>We can loop through a tuple using a for loop or a while loop.</p><h4><strong>Example Using for Loop</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*tcN948UgSfvaLdJzcQcLmw.png" /></figure><h4><strong>Example Using while Loop</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*2y-b_g_2Ok5BvrADqsaRGQ.png" /></figure><h4><strong>Indexing</strong></h4><p>We can access a single element in a tuple using Indexing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*9o8z4OaY8Gb4pS0ok0MrIg.png" /><figcaption>Indexing</figcaption></figure><h4><strong>Slicing</strong></h4><p>We can access multiple elements from a tuple using Slicing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*iBENal4_smau0CraJZw2kw.png" /><figcaption>Slicing</figcaption></figure><h4>Important Note</h4><p>Since tuples are immutable, the following operations are not allowed:</p><p>Adding elements</p><p>Replacing elements</p><p>Deleting elements</p><h4>Difference Between List and Tuple</h4><p>A list and a tuple are both collection data types used to store multiple values. They can store elements of the same or different data types, support indexing and slicing, and allow duplicate elements</p><p>A list is mutable, which means its elements can be added, replaced, or deleted after the list is created. Lists are created using square brackets [] and provide many built-in methods such as append() , insert() , remove() , pop() , and sort() . Lists are mainly used when the data is expected to change.</p><p>A tuple is immutable, which means its elements cannot be added, replaced, or deleted after the tuple is created. Tuples are created using parentheses () . Tuples are mainly used when the data should remain fixed and unchanged.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7feaa0e41093" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>