<?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 CHANDANA VEERABATHINI on Medium]]></title>
        <description><![CDATA[Stories by CHANDANA VEERABATHINI on Medium]]></description>
        <link>https://medium.com/@chandanaveerabathini?source=rss-3fb2b3c881a3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IDXS7COeeh2yemjo</url>
            <title>Stories by CHANDANA VEERABATHINI on Medium</title>
            <link>https://medium.com/@chandanaveerabathini?source=rss-3fb2b3c881a3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:24:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chandanaveerabathini/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[Collections in Python ]]></title>
            <link>https://medium.com/@chandanaveerabathini/collections-in-python-477c6e072790?source=rss-3fb2b3c881a3------2</link>
            <guid isPermaLink="false">https://medium.com/p/477c6e072790</guid>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[data-dictionary]]></category>
            <category><![CDATA[tuples-in-python]]></category>
            <category><![CDATA[collections-in-python]]></category>
            <category><![CDATA[sets-in-python]]></category>
            <dc:creator><![CDATA[CHANDANA VEERABATHINI]]></dc:creator>
            <pubDate>Mon, 31 Aug 2026 14:57:10 GMT</pubDate>
            <atom:updated>2026-08-31T14:57:10.843Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with Python, we often need to <strong>store and manage multiple pieces of data</strong> together. Python provides several built-in data structures, commonly referred to as <strong>collections</strong>, that make this easier.</p><p>The most commonly used collections are <strong>String, List, Tuple, Set, and Dictionary</strong>. Each collection has its own way of storing data and different features that make it suitable for specific situations.</p><p>For example, a <strong>String</strong> is used to store text, a <strong>List</strong> stores an ordered and changeable collection of items, a <strong>Tuple</strong> stores fixed data, a <strong>Set</strong> stores unique elements, and a <strong>Dictionary</strong> stores data as key-value pairs.</p><p>Understanding these collections is one of the <strong>fundamental steps in learning Python</strong>, as they are used in almost every Python program.</p><p>In this blog, let’s explore these collections, their important features, commonly used methods, and simple examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6-fCSY2kFsTF2nEpkc6zg.png" /><figcaption>Representation of Collection DataTypes</figcaption></figure><h3>Collections and Data Types in Python</h3><p>Python provides different data types to store and organize data. Among them, <strong>String, List, Tuple, Set, and Dictionary</strong> are commonly used to store collections of values.</p><p>Each collection has different features and is useful in different situations.</p><h3>1. String</h3><p>A <strong>String</strong> is a sequence of characters enclosed in single quotes (&#39; &#39;), double quotes (&quot; &quot;), or triple quotes.</p><pre>name = &quot;Python&quot;</pre><pre>print(name)</pre><p>Output:</p><pre>Python</pre><h4>Accessing Characters</h4><p>Each character in a string has an index starting from 0.</p><pre>name = &quot;Python&quot;</pre><pre>print(name[0])<br>print(name[2])</pre><p>Output:</p><pre>P<br>t</pre><h4>Important String Methods</h4><p><strong>upper()</strong> – Converts the string to uppercase.</p><pre>text = &quot;python&quot;</pre><pre>print(text.upper())</pre><p>Output:</p><pre>PYTHON</pre><p><strong>lower()</strong> – Converts the string to lowercase.</p><pre>text = &quot;PYTHON&quot;</pre><pre>print(text.lower())</pre><p>Output:</p><pre>python</pre><p><strong>replace()</strong> – Replaces one part of a string with another.</p><pre>text = &quot;I like Java&quot;</pre><pre>print(text.replace(&quot;Java&quot;, &quot;Python&quot;))</pre><p>Output:</p><pre>I like Python</pre><p><strong>split()</strong> – Splits a string into a list.</p><pre>text = &quot;Python is easy&quot;</pre><pre>print(text.split())</pre><p>Output:</p><pre>[&#39;Python&#39;, &#39;is&#39;, &#39;easy&#39;]</pre><p><strong>strip()</strong> – Removes spaces from the beginning and end.</p><pre>text = &quot;  Python  &quot;</pre><pre>print(text.strip())</pre><p>Output:</p><pre>Python</pre><blockquote><strong><em>Note:</em></strong><em> Strings are </em><strong><em>immutable</em></strong><em>, which means their individual characters cannot be changed after creation.</em></blockquote><h3>2. List</h3><p>A <strong>List</strong> is an ordered and mutable collection. It can contain duplicate values and different data types.</p><pre>fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Mango&quot;]</pre><pre>print(fruits)</pre><p>Output:</p><pre>[&#39;Apple&#39;, &#39;Banana&#39;, &#39;Mango&#39;]</pre><h4>Accessing List Elements</h4><pre>fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Mango&quot;]</pre><pre>print(fruits[0])</pre><p>Output:</p><pre>Apple</pre><h4>Important List Methods</h4><p><strong>append()</strong> – Adds an element at the end.</p><pre>numbers = [1, 2, 3]</pre><pre>numbers.append(4)</pre><pre>print(numbers)</pre><p>Output:</p><pre>[1, 2, 3, 4]</pre><p><strong>insert()</strong> – Adds an element at a specific position.</p><pre>numbers = [1, 2, 4]</pre><pre>numbers.insert(2, 3)</pre><pre>print(numbers)</pre><p>Output:</p><pre>[1, 2, 3, 4]</pre><p><strong>remove()</strong> – Removes a specific element.</p><pre>fruits = [&quot;Apple&quot;, &quot;Banana&quot;, &quot;Mango&quot;]</pre><pre>fruits.remove(&quot;Banana&quot;)</pre><pre>print(fruits)</pre><p>Output:</p><pre>[&#39;Apple&#39;, &#39;Mango&#39;]</pre><p><strong>pop()</strong> – Removes an element using its index. By default, it removes the last element.</p><pre>numbers = [10, 20, 30]</pre><pre>numbers.pop()</pre><pre>print(numbers)</pre><p>Output:</p><pre>[10, 20]</pre><p><strong>sort()</strong> – Sorts the list.</p><pre>numbers = [5, 2, 8, 1]</pre><pre>numbers.sort()</pre><pre>print(numbers)</pre><p>Output:</p><pre>[1, 2, 5, 8]</pre><p><strong>reverse()</strong> – Reverses the list.</p><pre>numbers = [1, 2, 3]</pre><pre>numbers.reverse()</pre><pre>print(numbers)</pre><p>Output:</p><pre>[3, 2, 1]</pre><h3>3. Tuple</h3><p>A <strong>Tuple</strong> is an ordered collection that cannot be changed after it is created.</p><pre>colors = (&quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot;)</pre><pre>print(colors)</pre><p>Output:</p><pre>(&#39;Red&#39;, &#39;Green&#39;, &#39;Blue&#39;)</pre><h4>Accessing Tuple Elements</h4><pre>colors = (&quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot;)</pre><pre>print(colors[0])</pre><p>Output:</p><pre>Red</pre><h4>Important Tuple Methods</h4><p>Since tuples are immutable, they have only a few methods.</p><p><strong>count()</strong> – Counts how many times a value occurs.</p><pre>numbers = (1, 2, 2, 3, 2)</pre><pre>print(numbers.count(2))</pre><p>Output:</p><pre>3</pre><p><strong>index()</strong> – Returns the position of a value.</p><pre>colors = (&quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot;)</pre><pre>print(colors.index(&quot;Green&quot;))</pre><p>Output:</p><pre>1</pre><blockquote><strong><em>Note:</em></strong><em> Tuples are useful when we want to keep data fixed and prevent accidental changes.</em></blockquote><h3>4. Set</h3><p>A <strong>Set</strong> is an unordered collection of unique elements.</p><p>Duplicate values are automatically removed.</p><pre>numbers = {1, 2, 3, 2, 1}</pre><pre>print(numbers)</pre><p>Output:</p><pre>{1, 2, 3}</pre><h4>Important Set Methods</h4><p><strong>add()</strong> – Adds an element.</p><pre>numbers = {1, 2, 3}</pre><pre>numbers.add(4)</pre><pre>print(numbers)</pre><p><strong>remove()</strong> – Removes an element.</p><pre>numbers = {1, 2, 3}</pre><pre>numbers.remove(2)</pre><pre>print(numbers)</pre><p><strong>union()</strong> – Combines two sets.</p><pre>a = {1, 2, 3}<br>b = {3, 4, 5}</pre><pre>print(a.union(b))</pre><p>Output:</p><pre>{1, 2, 3, 4, 5}</pre><p><strong>intersection()</strong> – Returns common elements.</p><pre>a = {1, 2, 3}<br>b = {2, 3, 4}</pre><pre>print(a.intersection(b))</pre><p>Output:</p><pre>{2, 3}</pre><p><strong>difference()</strong> – Returns elements that are present in the first set but not in the second.</p><pre>a = {1, 2, 3}<br>b = {2, 3, 4}</pre><pre>print(a.difference(b))</pre><p>Output:</p><pre>{1}</pre><h3>5. Dictionary</h3><p>A <strong>Dictionary</strong> stores data in the form of <strong>key-value pairs</strong>.</p><pre>student = {<br>    &quot;name&quot;: &quot;Chandana&quot;,<br>    &quot;age&quot;: 21,<br>    &quot;course&quot;: &quot;CSE&quot;<br>}</pre><pre>print(student)</pre><p>Output:</p><pre>{&#39;name&#39;: &#39;Chandana&#39;, &#39;age&#39;: 21, &#39;course&#39;: &#39;CSE&#39;}</pre><h4>Accessing Dictionary Values</h4><pre>print(student[&quot;name&quot;])</pre><p>Output:</p><pre>Chandana</pre><h4>Important Dictionary Methods</h4><p><strong>get()</strong> – Gets the value of a key.</p><pre>print(student.get(&quot;age&quot;))</pre><p>Output:</p><pre>21</pre><p><strong>keys()</strong> – Returns all keys.</p><pre>print(student.keys())</pre><p><strong>values()</strong> – Returns all values.</p><pre>print(student.values())</pre><p><strong>items()</strong> – Returns all key-value pairs.</p><pre>print(student.items())</pre><p><strong>update()</strong> – Adds or changes values.</p><pre>student.update({&quot;age&quot;: 22})</pre><pre>print(student)</pre><p><strong>pop()</strong> – Removes a key-value pair.</p><pre>student.pop(&quot;age&quot;)</pre><pre>print(student)</pre><p><strong>clear()</strong> – Removes all elements.</p><pre>student.clear()</pre><pre>print(student)</pre><p>Output:</p><pre>{}</pre><h3>Comparison of Python Collections</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bzzDNUVQetV8EC04ha719Q.png" /><figcaption>difference between dataStructures</figcaption></figure><h3>When to Use Each Collection?</h3><h4>String :</h4><p>Use a <strong>String</strong> when working with text.</p><pre>name = &quot;Chandana&quot;</pre><h4>List :</h4><p>Use a <strong>List</strong> when you need an ordered collection that can be changed.</p><pre>marks = [80, 75, 90]</pre><h4>Tuple :</h4><p>Use a <strong>Tuple</strong> when the data should remain unchanged.</p><pre>coordinates = (10, 20)</pre><h4>Set :</h4><p>Use a <strong>Set</strong> when you need only unique values.</p><pre>unique_numbers = {1, 2, 3}</pre><h4><strong><em>Dictionary :</em></strong></h4><p>Use a <strong>Dictionary</strong> when you need to store information as key-value pairs.</p><pre>student = {<br>    &quot;name&quot;: &quot;Chandana&quot;,<br>    &quot;age&quot;: 21<br>}</pre><h3><strong><em>— — — — Conclusion — — — —</em></strong></h3><p>Python collections make it easy to store, access, and manage data.</p><p><strong>String</strong> is mainly used for text, <strong>List</strong> is used for ordered and changeable data, <strong>Tuple</strong> is used for fixed data, <strong>Set</strong> is used for unique values, and <strong>Dictionary</strong> is used for key-value data.</p><p>Understanding these collections and their methods is an important step toward becoming comfortable with Python programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F7cmthW1nDgWMbkBn-7YXw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477c6e072790" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>