{"id":449,"date":"2019-07-19T09:21:53","date_gmt":"2019-07-19T09:21:53","guid":{"rendered":"http:\/\/askpython.com\/?p=449"},"modified":"2019-09-04T12:00:49","modified_gmt":"2019-09-04T12:00:49","slug":"python-tuple","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python\/tuple\/python-tuple","title":{"rendered":"Python Tuple &#8211; An Immutable Sequence"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>Python tuple is an immutable sequence.<\/li><li>The tuple is created with values separated by a comma.<\/li><li>Since a tuple is immutable, we can&#8217;t add or delete its elements.<\/li><li>If the tuple elements are not immutable, their properties can be changed. But, we can&#8217;t directly change a tuple element.<\/li><li>We can create nested tuples.<\/li><li>We can access tuple elements through their index. It also supports negative indexing to refer elements from the end to start.<\/li><li>We can also unpack tuple elements to comma-separated values.<\/li><li>Tuples are usually created to store heterogeneous elements. They can also have <strong>None<\/strong>.<\/li><li>Tuples support two <a rel=\"noreferrer noopener\" label=\"operators (opens in a new tab)\" href=\"https:\/\/www.askpython.com\/python\/python-operators\" target=\"_blank\">operators<\/a>: + for concatenation and * for repeating the elements.<\/li><li>Tuple supports slicing to create another tuple from the source tuple.<\/li><li>We can use &#8220;in&#8221; and &#8220;not in&#8221; operators with a tuple to check if the item is present in the tuple or not.<\/li><li>Since a tuple is a sequence, we can iterate over its elements using the <a rel=\"noreferrer noopener\" label=\"for loop (opens in a new tab)\" href=\"https:\/\/www.askpython.com\/python\/python-for-loop\" target=\"_blank\">for loop<\/a>.<\/li><li>Python tuple class has two <a rel=\"noreferrer noopener\" aria-label=\"functions (opens in a new tab)\" href=\"https:\/\/www.askpython.com\/python\/python-functions\" target=\"_blank\">functions<\/a> &#8211; <code>count()<\/code> and <code>index()<\/code>.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to Create a Tuple in Python?<\/h2>\n\n\n\n<p>We can create a tuple by placing all of its elements inside parentheses separated by a comma.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntuple_numbers = (1, 2, 3, 1)\n<\/pre><\/div>\n\n\n<p>We can keep different types of objects in a tuple.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntup = 1, 2, 3, 1, None, &quot;Hello&quot;\n<\/pre><\/div>\n\n\n<p>Let&#8217;s look at an example of a nested tuple.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nnested_tuple = ((1, 2), (&quot;Hello&quot;, &quot;Hi&quot;), &quot;Python&quot;)\n<\/pre><\/div>\n\n\n<p>We can create an empty tuple by not having any element inside the parentheses.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nempty_tuple = ()\n<\/pre><\/div>\n\n\n<p>The use of parentheses to create the boundary of a tuple is optional. However, it&#8217;s the best practice to use it. If you print a tuple, the elements are always printed inside the parentheses.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tup = 1, 2, &quot;Hello&quot;\n&gt;&gt;&gt; print(tup)\n(1, 2, &#039;Hello&#039;)\n&gt;&gt;&gt;\n<\/pre><\/div>\n\n\n<p>Creating a single item tuple is a bit tricky. If you place a single value inside the parentheses, it won&#8217;t create a tuple. It will create the object of the type of the value. Let&#8217;s check this behavior with a simple example.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nsingle_item_tuple = (&quot;Hello&quot;)\n\nprint(type(single_item_tuple))\n\nsingle_item_tuple = (10)\n\nprint(type(single_item_tuple))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"546\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-example.png\" alt=\"Python Tuple Example\" class=\"wp-image-451\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-example.png 666w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-example-300x246.png 300w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n\n<p>We can add a comma after the value to create a tuple with a single element.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nsingle_item_tuple = &quot;Hello&quot;,\n\nprint(type(single_item_tuple))\n\nsingle_item_tuple = 10,\n\nprint(type(single_item_tuple))\n<\/pre><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"504\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-with-single-element.png\" alt=\"Python Tuple With Single Element\" class=\"wp-image-452\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-with-single-element.png 652w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-with-single-element-300x232.png 300w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><figcaption>Python Tuple With Single Element<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to Access Tuple Elements?<\/h2>\n\n\n\n<p>We can access tuple elements through their index. The index value starts from 0 to the length of the tuple &#8211; 1.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntuple_numbers = (1, 2, 3, 4)\n\nprint(f&#039;First element in tuple is {tuple_numbers&#x5B;0]}&#039;)\nprint(f&#039;Third element in tuple is {tuple_numbers&#x5B;3]}&#039;)\n<\/pre><\/div>\n\n\n<p>If the tuple size is smaller than the specified index, &#8220;<strong>IndexError: tuple index out of range<\/strong>&#8221; is thrown.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tuple_numbers = (1, 2, 3, 4)\n&gt;&gt;&gt; tuple_numbers&#x5B;10]\nTraceback (most recent call last):\n  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;\nIndexError: tuple index out of range\n&gt;&gt;&gt;\n<\/pre><\/div>\n\n\n<p>Tuple also supports negative indexing. In this case, the tuple element is retrieved from the end to the start. The negative index starts from -1 to the -(length of the tuple).<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntuple_numbers = (1, 2, 3, 4)\n\nprint(f&#039;Last element in tuple is {tuple_numbers&#x5B;-1]}&#039;)\nprint(f&#039;Second Last element in tuple is {tuple_numbers&#x5B;-2]}&#039;)\nprint(f&#039;First element in tuple is {tuple_numbers&#x5B;-4]}&#039;)\n<\/pre><\/div>\n\n\n<p>If we have a nested tuple, we can access its elements through nested indexes.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; nested_tuple = (1, 2, (3, 4), (5, 6, 7))\n&gt;&gt;&gt; nested_tuple&#x5B;2]&#x5B;0]\n3\n&gt;&gt;&gt; nested_tuple&#x5B;2]&#x5B;1]\n4\n&gt;&gt;&gt; nested_tuple&#x5B;3]&#x5B;0]\n5\n&gt;&gt;&gt; nested_tuple&#x5B;3]&#x5B;1]\n6\n&gt;&gt;&gt; nested_tuple&#x5B;3]&#x5B;2]\n7\n&gt;&gt;&gt;\n<\/pre><\/div>\n\n\n<p>We can use negative indexes with the nested tuples too.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; nested_tuple = (1, 2, (3, 4), (5, 6, 7))\n&gt;&gt;&gt; \n&gt;&gt;&gt; nested_tuple&#x5B;-1]&#x5B;-1]\n7\n&gt;&gt;&gt; nested_tuple&#x5B;-2]&#x5B;1]\n4\n&gt;&gt;&gt; nested_tuple&#x5B;-2]&#x5B;-1]\n4\n&gt;&gt;&gt; nested_tuple&#x5B;3]&#x5B;-2]\n6\n&gt;&gt;&gt; \n<\/pre><\/div>\n\n\n<p>The below image shows how the indexes work in a tuple.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"286\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-index-1024x286.png\" alt=\"Python Tuple Index\" class=\"wp-image-458\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-index-1024x286.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-index-300x84.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-index-768x214.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-index.png 1146w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Python Tuple Index<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Slicing a Tuple<\/h2>\n\n\n\n<p>We can use slicing to create a subset of a tuple. This is useful in creating a new tuple from a source tuple. The slicing technique contains two indexes separated using a colon. The left index is included and the right index is excluded from the result.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntuple_numbers = (1, 2, 3, 4, 5, 6, 7, 8)\n\nprint(tuple_numbers&#x5B;1:3])\nprint(tuple_numbers&#x5B;:4])\nprint(tuple_numbers&#x5B;5:])\nprint(tuple_numbers&#x5B;:-5])\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"544\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/slicing-tuple-in-python.png\" alt=\"Slicing Tuple In Python\" class=\"wp-image-455\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/slicing-tuple-in-python.png 690w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/slicing-tuple-in-python-300x237.png 300w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><figcaption>Slicing Tuple in Python<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Tuple is immutable<\/h2>\n\n\n\n<p>A tuple is immutable in nature. So we can&#8217;t add, update or delete its elements. However, if the element is mutable then its properties can change.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tup = (1,2)\n&gt;&gt;&gt; tup&#x5B;0] = 10\nTraceback (most recent call last):\n  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;\nTypeError: &#039;tuple&#039; object does not support item assignment\n<\/pre><\/div>\n\n\n<p>Let&#8217;s see an example where the tuple elements are mutable and we change their properties.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist_fruits = &#x5B;&quot;Apple&quot;]\n\ntup = (&quot;Hello&quot;, list_fruits)\n\nprint(tup)\n\nlist_fruits.append(&quot;Banana&quot;)\n\nprint(tup)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"672\" height=\"558\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-with-mutable-elements.png\" alt=\"Python Tuple With Mutable Elements\" class=\"wp-image-460\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-with-mutable-elements.png 672w, https:\/\/www.askpython.com\/wp-content\/uploads\/2019\/07\/python-tuple-with-mutable-elements-300x249.png 300w\" sizes=\"auto, (max-width: 672px) 100vw, 672px\" \/><figcaption>Python Tuple With Mutable Elements<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Deleting a Tuple<\/h2>\n\n\n\n<p>We can&#8217;t delete elements of a tuple. But, we can delete the tuple itself using the <strong>del<\/strong> statement.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tup = (1,2)\n&gt;&gt;&gt; print(tup)\n(1, 2)\n&gt;&gt;&gt; del tup\n&gt;&gt;&gt; print(tup)\nTraceback (most recent call last):\n  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;\nNameError: name &#039;tup&#039; is not defined\n&gt;&gt;&gt;\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Tuple Concatenation (+ operator)<\/h2>\n\n\n\n<p>We can concatenate tuple elements to create a new tuple using the + operator.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tuple1 = (1, 2)\n&gt;&gt;&gt; tuple2 = (3, 4)\n&gt;&gt;&gt; tuple3 = (5, 6, 7)\n&gt;&gt;&gt; \n&gt;&gt;&gt; tuple_all = tuple1 + tuple2 + tuple3\n&gt;&gt;&gt; print(tuple_all)\n(1, 2, 3, 4, 5, 6, 7)\n&gt;&gt;&gt; \n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Repeating Tuple Elements (* operator)<\/h2>\n\n\n\n<p>Tuple also supports * operator to create a new tuple with the elements repeated the given number of times.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tup = (1, 2, (3, 4))\n&gt;&gt;&gt; \n&gt;&gt;&gt; tup1 = tup * 3\n&gt;&gt;&gt; \n&gt;&gt;&gt; print(tup1)\n(1, 2, (3, 4), 1, 2, (3, 4), 1, 2, (3, 4))\n&gt;&gt;&gt; \n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python Tuple Functions<\/h2>\n\n\n\n<p>The tuple class has two functions.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>count(x)<\/strong>: returns the number of occurrences of the given element.<\/li><li><strong>index(x, start, end)<\/strong>: returns the first index of the value. We can specify the start and end index to look for the value in the tuple. If the value is not found, <strong>ValueError<\/strong> is raised.<\/li><\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; tup = (1, 2, 3, 1, 2, 1, 3, 2, 1)\n&gt;&gt;&gt; \n&gt;&gt;&gt; tup.count(1)\n4\n&gt;&gt;&gt; tup.count(2)\n3\n&gt;&gt;&gt; tup.index(2)\n1\n&gt;&gt;&gt; tup.index(2, 2)\n4\n&gt;&gt;&gt; tup.index(2, 2, 6)\n4\n&gt;&gt;&gt; tup.index(20)\nTraceback (most recent call last):\n  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;\nValueError: tuple.index(x): x not in tuple\n&gt;&gt;&gt; \n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Tuple Membership Test (in, not in operators)<\/h2>\n\n\n\n<p>We can check if the tuple contains an element using the &#8220;in&#8221; operator. Similarly, we can use &#8220;not in&#8221; operator to test if the element is not present in the tuple.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; vowels = (&quot;a&quot;, &quot;e&quot;, &quot;i&quot;, &quot;o&quot;, &quot;u&quot;)\n&gt;&gt;&gt; \n&gt;&gt;&gt; &quot;a&quot; in vowels\nTrue\n&gt;&gt;&gt; &quot;x&quot; in vowels\nFalse\n&gt;&gt;&gt; \n&gt;&gt;&gt; &quot;a&quot; not in vowels\nFalse\n&gt;&gt;&gt; &quot;x&quot; not in vowels\nTrue\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Iterating through a tuple<\/h2>\n\n\n\n<p>We can use for loop to iterate through the elements of a tuple.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nvowels = (&quot;a&quot;, &quot;e&quot;, &quot;i&quot;, &quot;o&quot;, &quot;u&quot;)\n\nfor v in vowels:\n    print(v)\n<\/pre><\/div>\n\n\n<p>If you want to iterate through the tuple in the reverse order, you can use reversed() function.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfor v in reversed(vowels):\n    print(v)\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Tuple vs List<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>A tuple is immutable whereas List is mutable.<\/li><li>The tuple is preferred over List to store different types of <a href=\"https:\/\/www.askpython.com\/python\/python-data-types\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"data types (opens in a new tab)\">data types<\/a> in a sequence.<\/li><li>Since a tuple is immutable, iterating through the tuple is slightly faster than a list.<\/li><li>A tuple is more memory and space-optimized than a List.<\/li><li>If you want to add, delete elements from a sequence then use List.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python tuple() built-in function<\/h2>\n\n\n\n<p>We can also use the tuple() function to create a tuple. It accepts an iterable argument such as List and String. It&#8217;s useful in converting other sequence types to a tuple.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Python List to Tuple<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist_numbers = &#x5B;1, 2, 3]\n\ntuple_numbers = tuple(list_numbers)\nprint(tuple_numbers)  # (1, 2, 3)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">2. Python String to Tuple<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ns = &quot;ABCD&quot;\ntuple_str = tuple(s)\nprint(tuple_str)  # (&#039;A&#039;, &#039;B&#039;, &#039;C&#039;, &#039;D&#039;)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">3. Python range to Tuple<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nr = range(1, 10)\ntuple_range = tuple(r)\nprint(tuple_range)\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>A tuple is an immutable sequence in Python. When you want to have a read-only sequence, use a tuple.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">References:<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" aria-label=\"tuple() built-in function (opens in a new tab)\" href=\"https:\/\/docs.python.org\/3\/library\/functions.html#func-tuple\" target=\"_blank\">tuple() built-in function<\/a><\/li><li><a href=\"https:\/\/docs.python.org\/3\/tutorial\/datastructures.html#tuples-and-sequences\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Tuple Data Structure (opens in a new tab)\">Tuple Data Structure<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Python tuple is an immutable sequence. The tuple is created with values separated by a comma. Since a tuple is immutable, we can&#8217;t add or delete its elements. If the tuple elements are not immutable, their properties can be changed. But, we can&#8217;t directly change a tuple element. We can create nested tuples. We can [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-tuple"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}