{"id":72,"date":"2026-03-01T16:45:32","date_gmt":"2026-03-01T11:45:32","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=72"},"modified":"2026-03-13T11:25:42","modified_gmt":"2026-03-13T06:25:42","slug":"tuples","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/tuples\/","title":{"rendered":"Tuples"},"content":{"rendered":"\n<p>A <strong>tuple<\/strong> is a collection data type in Python used to store multiple items in a single variable.<br>Tuples are <strong>ordered<\/strong>, <strong>immutable (unchangeable)<\/strong>, and allow <strong>duplicate values<\/strong>.<\/p>\n\n\n\n<p>Tuples are similar to lists, but the main difference is that tuples cannot be modified after creation.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CREATING A TUPLE<\/strong><\/h1>\n\n\n\n<p>Tuples are created using round 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>A tuple can contain 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>SINGLE-ITEM TUPLE<\/strong><\/h1>\n\n\n\n<p>To create a tuple with one item, you must add a comma.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">single = (5,)<\/pre>\n\n\n\n<p>Without the comma, it is not considered a tuple.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>ACCESSING TUPLE ELEMENTS<\/strong><\/h1>\n\n\n\n<p>Indexing works the same as lists. Index 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])  # Mango<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>SLICING A TUPLE<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = (1, 2, 3, 4, 5)<br>print(numbers[1:4])   # (2, 3, 4)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>TUPLES ARE IMMUTABLE<\/strong><\/h1>\n\n\n\n<p>You cannot change, add, or remove elements after creation.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fruits = (\"Apple\", \"Banana\", \"Mango\")<br># fruits[1] = \"Orange\"   # This will give an error<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CONVERTING TUPLE TO LIST<\/strong><\/h1>\n\n\n\n<p>If you need to modify a tuple, convert it into a list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">fruits = (\"Apple\", \"Banana\", \"Mango\")temp = list(fruits)<br>temp[1] = \"Orange\"<br>fruits = tuple(temp)print(fruits)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>LOOPING THROUGH A TUPLE<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = (1, 2, 3)for num in numbers:<br>    print(num)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>COMMON TUPLE METHODS<\/strong><\/h1>\n\n\n\n<p>Tuples have limited methods because they are immutable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = (1, 2, 3, 2, 4)print(numbers.count(2))   # Count occurrences<br>print(numbers.index(3))   # Find index<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>PACKING AND UNPACKING TUPLES<\/strong><\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">Packing<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">person = (\"Hira\", 25, \"Pakistan\")<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Unpacking<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">name, age, country = person<br>print(name)<br>print(age)<br>print(country)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHEN TO USE TUPLES<\/strong><\/h1>\n\n\n\n<p>\u2022 When data should not change<br>\u2022 For fixed collections (coordinates, records, etc.)<br>\u2022 Faster than lists in some cases<br>\u2022 Can be used as dictionary keys (if containing immutable items)<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IMPORTANT POINTS<\/strong><\/h1>\n\n\n\n<p>\u2022 Tuples are ordered and indexed<br>\u2022 Tuples are immutable<br>\u2022 Allow duplicate values<br>\u2022 Use parentheses ( )<\/p>\n\n\n\n<p>Understanding <strong>tuples<\/strong> helps you work with fixed and secure data in Python programs.<\/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 > Tuples<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773382356377\"><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":27,"template":"","class_list":["post-72","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>Tuples - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python tuples: create, access, slice, loop, unpack, and use immutable tuples for secure, fixed collections in programs.\" \/>\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\/tuples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tuples - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python tuples: create, access, slice, loop, unpack, and use immutable tuples for secure, fixed collections in programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/tuples\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-13T06:25:42+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\\\/tuples\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/tuples\\\/\",\"name\":\"Tuples - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-01T11:45:32+00:00\",\"dateModified\":\"2026-03-13T06:25:42+00:00\",\"description\":\"Learn Python tuples: create, access, slice, loop, unpack, and use immutable tuples for secure, fixed collections in programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/tuples\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/tuples\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/tuples\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON INTERMEDIATE (PYI) > Data Structures > Tuples\"}]},{\"@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":"Tuples - One Language. Endless Possibilities","description":"Learn Python tuples: create, access, slice, loop, unpack, and use immutable tuples for secure, fixed collections in programs.","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\/tuples\/","og_locale":"en_US","og_type":"article","og_title":"Tuples - One Language. Endless Possibilities","og_description":"Learn Python tuples: create, access, slice, loop, unpack, and use immutable tuples for secure, fixed collections in programs.","og_url":"https:\/\/gigz.pk\/python\/lesson\/tuples\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-13T06:25:42+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\/tuples\/","url":"https:\/\/gigz.pk\/python\/lesson\/tuples\/","name":"Tuples - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-01T11:45:32+00:00","dateModified":"2026-03-13T06:25:42+00:00","description":"Learn Python tuples: create, access, slice, loop, unpack, and use immutable tuples for secure, fixed collections in programs.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/tuples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/tuples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/tuples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON INTERMEDIATE (PYI) > Data Structures > Tuples"}]},{"@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\/72","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=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}