{"id":71,"date":"2026-03-01T16:41:24","date_gmt":"2026-03-01T11:41:24","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=71"},"modified":"2026-03-13T11:00:05","modified_gmt":"2026-03-13T06:00:05","slug":"lists","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/lists\/","title":{"rendered":"Lists"},"content":{"rendered":"\n<p>A <strong>list<\/strong> is a collection data type in Python used to store multiple items in a single variable.<br>Lists are <strong>ordered<\/strong>, <strong>changeable (mutable)<\/strong>, and allow <strong>duplicate values<\/strong>.<\/p>\n\n\n\n<p>Lists are one of the most commonly used data structures in Python.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CREATING A LIST<\/strong><\/h1>\n\n\n\n<p>Lists are created using square brackets <code>[ ]<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = [1, 2, 3, 4, 5]<\/pre>\n\n\n\n<p>Lists can store different data types:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mixed = [10, \"Python\", 3.14, True]<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>ACCESSING LIST ELEMENTS<\/strong><\/h1>\n\n\n\n<p>List items are accessed using indexing.<br>Indexing starts from 0.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fruits = [\"Apple\", \"Banana\", \"Mango\"]print(fruits[0])   # Apple<br>print(fruits[1])   # Banana<\/pre>\n\n\n\n<p>Negative indexing is also allowed:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(fruits[-1])  # Mango<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>SLICING A LIST<\/strong><\/h1>\n\n\n\n<p>Slicing allows you to get a range of elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = [1, 2, 3, 4, 5]print(numbers[1:4])   # [2, 3, 4]<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>MODIFYING LIST ELEMENTS<\/strong><\/h1>\n\n\n\n<p>Lists are mutable, meaning you can change their values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fruits = [\"Apple\", \"Banana\", \"Mango\"]<br>fruits[1] = \"Orange\"print(fruits)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>ADDING ELEMENTS TO A LIST<\/strong><\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">append() \u2013 Adds item at the end<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = [1, 2, 3]<br>numbers.append(4)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">insert() \u2013 Adds item at specific position<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers.insert(1, 10)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">extend() \u2013 Adds multiple items<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers.extend([5, 6])<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>REMOVING ELEMENTS FROM A LIST<\/strong><\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">remove() \u2013 Removes specific value<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers.remove(10)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">pop() \u2013 Removes item by index<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers.pop(0)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">clear() \u2013 Removes all items<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers.clear()<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>LOOPING THROUGH A LIST<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">fruits = [\"Apple\", \"Banana\", \"Mango\"]for fruit in fruits:<br>    print(fruit)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>COMMON LIST FUNCTIONS<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = [5, 2, 8, 1]print(len(numbers))      # Length<br>print(max(numbers))      # Maximum value<br>print(min(numbers))      # Minimum valuenumbers.sort()           # Sort list<br>numbers.reverse()        # Reverse list<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>LIST COMPREHENSION<\/strong><\/h1>\n\n\n\n<p>A shorter way to create lists.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">squares = [x * x for x in range(5)]<br>print(squares)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IMPORTANT POINTS<\/strong><\/h1>\n\n\n\n<p>\u2022 Lists are ordered and indexed<br>\u2022 Lists are mutable (can be changed)<br>\u2022 Allow duplicate values<br>\u2022 Can store multiple data types<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHY LISTS ARE IMPORTANT<\/strong><\/h1>\n\n\n\n<p>\u2022 Store multiple values efficiently<br>\u2022 Useful in data processing<br>\u2022 Essential for loops and functions<br>\u2022 Widely used in real-world Python applications<\/p>\n\n\n\n<p>Understanding <strong>lists<\/strong> is fundamental for working with data in Python.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON INTERMEDIATE (PYI) > Data Structures > Lists<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773381625257\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":26,"template":"","class_list":["post-71","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Lists - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python lists: create, access, modify, loop, and use list methods &amp; comprehension for efficient data handling.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lists - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python lists: create, access, modify, loop, and use list methods &amp; comprehension for efficient data handling.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/lists\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-13T06:00:05+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lists\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lists\\\/\",\"name\":\"Lists - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-01T11:41:24+00:00\",\"dateModified\":\"2026-03-13T06:00:05+00:00\",\"description\":\"Learn Python lists: create, access, modify, loop, and use list methods & comprehension for efficient data handling.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lists\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lists\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lists\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON INTERMEDIATE (PYI) > Data Structures > Lists\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Lists - One Language. Endless Possibilities","description":"Learn Python lists: create, access, modify, loop, and use list methods & comprehension for efficient data handling.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/python\/lesson\/lists\/","og_locale":"en_US","og_type":"article","og_title":"Lists - One Language. Endless Possibilities","og_description":"Learn Python lists: create, access, modify, loop, and use list methods & comprehension for efficient data handling.","og_url":"https:\/\/gigz.pk\/python\/lesson\/lists\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-13T06:00:05+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/lists\/","url":"https:\/\/gigz.pk\/python\/lesson\/lists\/","name":"Lists - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-01T11:41:24+00:00","dateModified":"2026-03-13T06:00:05+00:00","description":"Learn Python lists: create, access, modify, loop, and use list methods & comprehension for efficient data handling.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/lists\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/lists\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON INTERMEDIATE (PYI) > Data Structures > Lists"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}