<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vijayan Chakravarthi</title>
    <description>The latest articles on DEV Community by Vijayan Chakravarthi (@codebyvj).</description>
    <link>https://dev.to/codebyvj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4097851%2F0f6c76e4-d049-4a43-980e-a29f85cc5311.png</url>
      <title>DEV Community: Vijayan Chakravarthi</title>
      <link>https://dev.to/codebyvj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codebyvj"/>
    <language>en</language>
    <item>
      <title>Lists in Python for Beginners</title>
      <dc:creator>Vijayan Chakravarthi</dc:creator>
      <pubDate>Thu, 27 Aug 2026 18:00:09 +0000</pubDate>
      <link>https://dev.to/codebyvj/lists-in-python-for-beginners-m43</link>
      <guid>https://dev.to/codebyvj/lists-in-python-for-beginners-m43</guid>
      <description>&lt;p&gt;A &lt;strong&gt;List&lt;/strong&gt; can be considered as a dynamic array. It is denoted by [ ]. The values inside a list are called &lt;strong&gt;elements&lt;/strong&gt;. The values in a list can be homogeneous (i.e., all elements are of the same data type) or they can be heterogeneous (i.e., a mix of multiple data types).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# An empty list
&lt;/span&gt;&lt;span class="n"&gt;list_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;                  

&lt;span class="c1"&gt;# A homogeneous list (all elements are of type integers)
&lt;/span&gt;&lt;span class="n"&gt;list_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  

&lt;span class="c1"&gt;# A heterogeneous list (mix of different types)
&lt;/span&gt;&lt;span class="n"&gt;list_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;language&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;c&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;e&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A list is &lt;strong&gt;dynamic&lt;/strong&gt; because the size of the array automatically changes with the addition or deletion of list elements. &lt;/p&gt;

&lt;p&gt;When an empty list is created, Python allocates 0 slots, but the moment you add your first element, it internally provisions 4 spaces in memory.            Subsequently, if those 4 spaces are filled, it expands the size of the list to 8 spaces, creating 4 additional slots. Specific calculations exist in Python's core logic behind this step-by-step expansion.&lt;/p&gt;

&lt;p&gt;Lists are &lt;strong&gt;ordered&lt;/strong&gt;, meaning the original order of insertion is maintained. If a new element is appended, it is automatically placed at the last position in the list. Lists also accept &lt;strong&gt;duplicate&lt;/strong&gt; elements.&lt;/p&gt;

&lt;p&gt;The operations that can be performed on a list can be obtained by running &lt;code&gt;dir(list_name)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The operations are performed using dot notation:&lt;br&gt;
e.g., To add an element, use: &lt;code&gt;list_name.append("New Value")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Accessing Elements via Indexing:&lt;/strong&gt;&lt;br&gt;
The elements in a list can be accessed using their index value. The index starts from 0 and extends to n-1 for a list of n elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;list_retrieval = [4, 3, 6, 7, 9, 1]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here:&lt;br&gt;
&lt;code&gt;list_retrieval[0]&lt;/code&gt; will return 4&lt;br&gt;
&lt;code&gt;list_retrieval[3]&lt;/code&gt; will return 7&lt;br&gt;
&lt;code&gt;list_retrieval[9]&lt;/code&gt; will throw an IndexError: list index out of range because index 9 does not exist.&lt;/p&gt;

&lt;p&gt;Similarly, elements can be accessed in reverse order. The last element is indicated by -1, and the first element is -n. Since our list has 6 elements (n=6), the first element can also be accessed at -6.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieving Subsets via Slicing:&lt;/strong&gt;&lt;br&gt;
The elements in a list can be retrieved in bulks using a 'slicing' operation: [start_index : end_index : step]&lt;/p&gt;

&lt;p&gt;Using our list_retrieval = [4, 3, 6, 7, 9, 1] example:&lt;/p&gt;

&lt;p&gt;Values from the beginning up to the 4th element can be retrieved as &lt;code&gt;list_retrieval[:4]&lt;/code&gt; or &lt;code&gt;list_retrieval[0:4]&lt;/code&gt;. The returned list is [4, 3, 6, 7].&lt;/p&gt;

&lt;p&gt;Values from the 3rd index to the end can be accessed as &lt;code&gt;list_retrieval[3:]&lt;/code&gt;. The returned list is [7, 9, 1].&lt;/p&gt;

&lt;p&gt;Values from the 2nd index to the 5th index (exclusive) can be accessed as &lt;code&gt;list_retrieval[2:5]&lt;/code&gt;. The returned list is [6, 7, 9].&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The starting index is inclusive and the ending index is exclusive. Meaning in [0:4], the 0th index is included, but the 4th index is excluded from the final result.&lt;/p&gt;

&lt;p&gt;The step parameter controls the increment between elements. By default, the step is &lt;code&gt;1&lt;/code&gt;, meaning it reads every consecutive element. &lt;br&gt;
If you set the step to &lt;code&gt;2&lt;/code&gt;, it skips every other element.&lt;/p&gt;

&lt;p&gt;Using our &lt;code&gt;list_retrieval = [4, 3, 6, 7, 9, 1]&lt;/code&gt; example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;list_retrieval[0:6:2]&lt;/code&gt;&lt;/strong&gt; will return &lt;code&gt;[4, 6, 9]&lt;/code&gt; (it starts at index 0 and takes every second element).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;list_retrieval[::-1]&lt;/code&gt;&lt;/strong&gt; is a famous Python trick! By omitting the start/end indexes and using a negative step of &lt;code&gt;-1&lt;/code&gt;, it returns the entire list completely reversed: &lt;code&gt;[1, 9, 7, 6, 3, 4]&lt;/code&gt;.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
