{"id":5799,"date":"2022-03-26T14:05:31","date_gmt":"2022-03-26T13:05:31","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=5799"},"modified":"2026-01-22T17:54:01","modified_gmt":"2026-01-22T16:54:01","slug":"tuples","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2022\/03\/26\/tuples\/","title":{"rendered":"Tuples"},"content":{"rendered":"<p>1. <strong>Tuples<\/strong> are ordered and unchangeable (immutable) collections of data. They can be thought of as immutable lists. They are written in round brackets:<\/p>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<div><!--more--><\/div>\n<div><\/div>\n<pre class=\"lang:default decode:true \">my_tuple = (1, 2, True, \"a string\", (3, 4), [5, 6], None)\r\nprint(my_tuple)\r\n\r\nmy_list = [1, 2, True, \"a string\", (3, 4), [5, 6], None]\r\nprint(my_list)<\/pre>\n<p>Each tuple element may be of a different type (i.e., integers, strings, booleans, etc.). What is more, tuples can contain other tuples or lists (and the other way round).<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>2. You can create an empty tuple like this:<\/p>\n<pre class=\"lang:default decode:true \">empty_tuple = ()\r\n\r\nprint(type(empty_tuple)) # outputs: &lt;class 'tuple'&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>3. A one-element tuple may be created as follows:<code class=\"codep syntax-color copy\"><\/code><\/p>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true \">one_elem_tuple_1 = (\"one\", ) # Brackets and a comma.\r\none_elem_tuple_2 = \"one\", # No brackets, just a comma.<\/pre>\n<p>If you remove the comma, you will tell Python to create a <b>variable<\/b>, not a tuple:<\/p>\n<\/div>\n<\/div>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true\">my_tuple_1 = 1,\r\nprint(type(my_tuple_1)) # outputs: &lt;class 'tuple'&gt;\r\n\r\nmy_tuple_2 = 1 # This is not a tuple.\r\nprint(type(my_tuple_2)) # outputs: &lt;class 'int'&gt;<\/pre>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>4. You can access tuple elements by indexing them:<\/p>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true \">my_tuple = (1, 2.0, \"string\", [3, 4], (5, ), True)\r\nprint(my_tuple[3]) # outputs: [3, 4]<\/pre>\n<p>&nbsp;<\/p>\n<p>5. Tuples are <b>immutable<\/b>, which means you cannot change their elements (you cannot append tuples, or modify, or remove tuple elements). The following snippet will cause an exception:<\/p>\n<\/div>\n<\/div>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true \">my_tuple = (1, 2.0, \"string\", [3, 4], (5, ), True)\r\nmy_tuple[2] = \"guitar\" # The TypeError exception will be raised.<\/pre>\n<p>However, you can delete a tuple as a whole:<\/p>\n<\/div>\n<\/div>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true \">my_tuple = 1, 2, 3,\r\ndel my_tuple\r\nprint(my_tuple) # NameError: name 'my_tuple' is not defined<\/pre>\n<p>&nbsp;<\/p>\n<p>6. You can loop through a tuple elements (Example 1), check if a specific element is (not)present in a tuple (Example 2), use the <code>len()<\/code> function to check how many elements there are in a tuple (Example 3), or even join\/multiply tuples (Example 4):<\/p>\n<div>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true\"># Example 1\r\ntuple_1 = (1, 2, 3)\r\nfor elem in tuple_1:\r\n  print(elem)\r\n\r\n# Example 2\r\ntuple_2 = (1, 2, 3, 4)\r\nprint(5 in tuple_2)\r\nprint(5 not in tuple_2)\r\n\r\n# Example 3\r\ntuple_3 = (1, 2, 3, 5)\r\nprint(len(tuple_3))\r\n\r\n# Example 4\r\ntuple_4 = tuple_1 + tuple_2\r\ntuple_5 = tuple_3 * 2\r\n\r\nprint(tuple_4)\r\nprint(tuple_5)<\/pre>\n<p>&nbsp;<\/p>\n<p>7. You can also create a tuple using a Python built-in function called <code>tuple()<\/code>. This is particularly useful when you want to convert a certain iterable (e.g., a list, range, string, etc.) to a tuple:<\/p>\n<\/div>\n<\/div>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true\">my_tuple = tuple((1, 2, \"string\"))\r\nprint(my_tuple)\r\n\r\nmy_list = [2, 4, 6]\r\nprint(my_list) # outputs: [2, 4, 6]\r\n\r\nprint(type(my_list)) # outputs: &lt;class 'list'&gt;\r\ntup = tuple(my_list)\r\n\r\nprint(tup) # outputs: (2, 4, 6)\r\nprint(type(tup)) # outputs: &lt;class 'tuple'&gt;<\/pre>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>By the same fashion, when you want to convert an iterable to a list, you can use a Python built-in function called <code>list()<\/code>:<\/p>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<pre class=\"lang:default decode:true\">tup = 1, 2, 3,\r\nmy_list = list(tup)\r\nprint(type(my_list)) # outputs: &lt;class 'list'&gt;<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><em>Exercise 1<\/em><\/p>\n<p>What happens when you attempt to run the following snippet?<\/p>\n<pre class=\"lang:default decode:true\">my_tup = (1, 2, 3) \r\nprint(my_tup[2])<\/pre>\n<p>&nbsp;<\/p>\n<p id=\"sol1\">The program will print <code>3<\/code> to the screen.<\/p>\n<p>&nbsp;<\/p>\n<p><em>Exercise 2<\/em><\/p>\n<p>What is the output of the following snippet?<\/p>\n<pre class=\"lang:default decode:true\">tup = 1, 2, 3\r\na, b, c = tup \r\nprint(a * b * c)<\/pre>\n<p>&nbsp;<\/p>\n<p id=\"sol2\">The program will print <code>6<\/code> to the screen. The <code>tup<\/code> tuple elements have been &#8220;unpacked&#8221; in the <code>a<\/code>, <code>b<\/code>, and <code>c<\/code> variables.<\/p>\n<p>&nbsp;<\/p>\n<p><em>Exercise 3<\/em><\/p>\n<p>Complete the code to correctly use the <code>count()<\/code> method to find the number of duplicates of <code>2<\/code> in the following tuple.<\/p>\n<pre class=\"lang:default decode:true\">tup = 1, 2, 3, 2, 4, 5, 6, 2, 7, 2, 8, 9 \r\nduplicates = # Write your code here. \r\n\r\nprint(duplicates) # outputs: 4<\/pre>\n<p>Solution:<\/p>\n<pre class=\"lang:default decode:true \">tup = 1, 2, 3, 2, 4, 5, 6, 2, 7, 2, 8, 9 \r\nduplicates = tup.count(2) \r\nprint(duplicates) # outputs: 4<\/pre>\n<p>&nbsp;<\/p>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<div>\n<div class=\"ace-tm\">\n<div class=\"ace_static_highlight\">\n<div class=\"ace_line\">Ex. 4<\/div>\n<\/div>\n<div>\n<p>What is the output of the following code snippet?<\/p>\n<pre class=\"lang:default decode:true \">tpl = ('a', 'b', 'c', 'd')\r\ndel tpl[-3:-1]\r\n\r\nprint(tpl)<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>A <code><strong>TypeError<\/strong><\/code> exception<\/p>\n<ul>\n<li><strong>Tuples<\/strong> are <strong>immutable<\/strong> and do not support item deletion.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Ex. 5<\/p>\n<div class=\"result-pane--question-header-wrapper--3DCpC\">\n<div class=\"result-pane--question-header--pTUOx\">\n<div id=\"question-prompt\" class=\"result-pane--question-format--PBvdY ud-text-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p>Which of the following statements about <strong>lists<\/strong> and <strong>tuples<\/strong> are <strong>false<\/strong>?<\/p>\n<p>(Select two answers)<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--question-result-pane-expanded-content--Og5Vc\">\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-incorrect--vFyOv\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code>Tuples have a fixed length, while lists have a variable length<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code>The <strong>sort()<\/strong>, <strong>insert()<\/strong>, and <strong>append()<\/strong> methods belong to both tuples and lists<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code>Lists are indexed while tuples are an unordered set<\/code><\/p>\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code>Tuples are immutable, while lists are mutable collections of data<\/code><\/p>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div><\/div>\n<div><\/div>\n<div><span class=\"result-pane--answer-by-user-label--PSH86 ud-heading-xs\" data-purpose=\"answer-result-header-user-label\">Correct selection<\/span><\/div>\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p>The <code><strong>sort()<\/strong><\/code>, <code><strong>insert()<\/strong><\/code>, and <code><strong>append()<\/strong><\/code> methods belong to both tuples and lists<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p>Lists are indexed while tuples are an unordered set<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<div id=\"overall-explanation\" class=\"ud-text-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<ul>\n<li>Both lists and tuples are <strong>indexed<\/strong> (with initial index equal to <code><strong>0<\/strong><\/code>).<\/li>\n<li><code><strong>sort()<\/strong><\/code>, <code><strong>pop()<\/strong><\/code>, and <code><strong>append()<\/strong><\/code> are list methods and cannot be used with tuples.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Ex. 6<\/p>\n<div class=\"result-pane--question-header-wrapper--3DCpC\">\n<div class=\"result-pane--question-header--pTUOx\">\n<div id=\"question-prompt\" class=\"result-pane--question-format--PBvdY ud-text-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p>According to the following code snippet, which of the following statements generates an <strong>exception<\/strong>?<\/p>\n<p>(Select two answers)<\/p>\n<div class=\"ud-component--base-components--code-block\">\n<div>\n<pre class=\"lang:default decode:true\">tpl = (3, 'xy', ['A', 'B'], 2, (9, 10))<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--question-result-pane-expanded-content--Og5Vc\">\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code><strong>a, b, c, d = tpl <\/strong><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code><strong>del tpl[3:]<\/strong><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-skipped--1NDPn\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code><strong>print(tpl[4][0])<\/strong><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-incorrect--vFyOv\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code><strong>print(tpl[2:100])<\/strong><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--question-related-fields--c3m--\">\n<div><\/div>\n<div class=\"overall-explanation-pane--overall-explanation--G-hLQ ud-form-group\">\n<p><span class=\"result-pane--answer-by-user-label--PSH86 ud-heading-xs\" data-purpose=\"answer-result-header-user-label\">Correct selections:<\/span><\/p>\n<div id=\"overall-explanation\" class=\"ud-text-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<div class=\"ud-component--base-components--code-block\">\n<div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code><strong>a, b, c, d = tpl <\/strong><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<p><code><strong>del tpl[3:]<\/strong><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<ul>\n<li><code><strong>del tpl[3:]<\/strong><\/code> &#8211; It throws a <code><strong>TypeError<\/strong><\/code> exception. The <code><strong>del<\/strong><\/code> statement cannot delete the elements of a tuple because tuples are <strong>immutable<\/strong>.<\/li>\n<li><code><strong>print(tpl[2:100])<\/strong><\/code> &#8211; It is <strong>correct<\/strong>. Even if the final index is out of range, the slice operator does not raise an error but takes all elements down to the last. Thus, in our case, it will take all elements starting from that of <strong>index <\/strong><code><strong>2<\/strong><\/code>, inclusive, up to the end of the tuple:<code><strong>print(tpl[2:100])<\/strong><\/code><strong> -&gt; <\/strong><code><strong>(['A', 'B'], 2, (9, 10))<\/strong><\/code>.<\/li>\n<li><code><strong>a, b, c, d = tpl<\/strong><\/code>\u00a0 &#8211; This is an example of <strong>unpacking<\/strong> tuples, but the statement is <strong>wrong<\/strong> because the number of variables to the left of the equal does not match the number of elements of the tuples to the right. It raises an <code><strong>ValueError<\/strong><\/code> exception:<strong>step by step<\/strong>Step 1 &#8211; <code><strong>a, b, c, d = tpl<\/strong><\/code>Step 2 &#8211; <code><strong>a, b, c, d = (3, 'xy', ['A', 'B'], 2, (9, 10))<\/strong><\/code>\n<p>Result &#8211; <code><strong>ValueError<\/strong><\/code><\/li>\n<li><code><strong>print(tpl[4][0])<\/strong><\/code><strong> &#8211; <\/strong>It is <strong>ok<\/strong>. The <code><strong>print()<\/strong><\/code> function prints the value of index <code><strong>0<\/strong><\/code> of the last element of <code><strong>tpl<\/strong><\/code>:<strong>step by step<\/strong>Step 1 &#8211; <code><strong>print(tpl[4][0])<\/strong><\/code>Step 2 &#8211; <code><strong>print((9, 10)[0])<\/strong><\/code>\n<p>Step 3 &#8211; <code><strong>print(9)<\/strong><\/code><\/p>\n<p>Output &#8211; <code><strong>9<\/strong><\/code><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Ex. 7<\/p>\n<p>Consider the code below:<\/p>\n<\/div>\n<pre class=\"lang:default decode:true \">    my_tuple = ('Luke', 'Leia', 'Han', 'Darth')\r\n    # Insert line of code here.\r\n    for x in my_v:\r\n        print(x, end=' ')<\/pre>\n<p>Which snippet would you insert in order for the program to output the following result:<\/p>\n<p><code>Leia Han Darth<\/code><\/p>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-correct--PLOEU\" data-purpose=\"answer\">\n<div><span class=\"result-pane--answer-by-user-label--PSH86 ud-heading-xs\" data-purpose=\"answer-result-header-user-label\">A:\u00a0 <\/span><code>my_v = [my_tuple[i] for i in range(1,4)]<\/code><\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--answer-result-pane--Niazi\">\n<div class=\"answer-result-pane--answer-skipped--1NDPn\" data-purpose=\"answer\">\n<div class=\"answer-result-pane--answer-body--cDGY6\" data-purpose=\"answer-body\">\n<div id=\"answer-text\" class=\"ud-heading-md rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<div class=\"ud-component--base-components--code-block\">\n<div>\n<p><span class=\"kwd\">B: <\/span><\/p>\n<pre class=\"lang:default decode:true \">del my_tuple[0]\r\nmy_v = my_tuple<\/pre>\n<p>C: <code>my_v = my_tuple.pop(0)<\/code><\/p>\n<p>D: <code>my_v = my_tuple[1:3]<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"result-pane--question-result-pane-expanded-content--Og5Vc\">\n<p><em>Explanation:<\/em><\/p>\n<p>A tuple is an <strong>immutable <\/strong>sequence type !<\/p>\n<p>So <code>del my_tuple[0] <\/code>\u00a0 is not permitted and will raise an exception.<\/p>\n<p><code>my_v = [my_tuple[i] for i in range(1,4)]<\/code>\u00a0 is a list comprehension and results in the following list:<\/p>\n<p><code>['Leia', 'Han', 'Darth']<\/code><\/p>\n<p>which when printed element by element (with the optional <code>end=' '<\/code> parameter within the <code>print()<\/code> function) gives :<\/p>\n<p><code>Leia Han Darth<\/code><\/p>\n<p><code>my_tuple[1:3] <\/code>(slicing) returns : <code>('Leia', 'Han')<\/code>\u00a0 (new tuple with only the elements with index 1 and 2 from the original tuple &#8211; remember element with index 3 is<strong> not included<\/strong> in the slice).<\/p>\n<p>Finally <code>my_tuple.pop(0)<\/code>\u00a0 will raise an exception since there is no such method with tuples (it does work with lists).<\/p>\n<p>Try it yourself:<\/p>\n<pre class=\"lang:default decode:true \">    my_tuple = ('Luke', 'Leia', 'Han', 'Darth')\r\n    del my_tuple[0]    # TypeError: 'tuple' object doesn't support item deletion\r\n    my_v = my_tuple\r\n    for x in my_v:\r\n        print(x, end=' ')\r\n     \r\n    print('\\n------')\r\n     \r\n    my_tuple = ('Luke', 'Leia', 'Han', 'Darth')\r\n    my_v = [my_tuple[i] for i in range(1,4)]\r\n    for x in my_v:\r\n        print(x, end=' ')  # Leia Han Darth \r\n     \r\n    print('\\n------')\r\n     \r\n    my_tuple = ('Luke', 'Leia', 'Han', 'Darth')\r\n    my_v = my_tuple[1:3]\r\n    for x in my_v:\r\n        print(x, end=' ')  # Leia Han \r\n     \r\n    print('\\n------')\r\n     \r\n    my_tuple = ('Luke', 'Leia', 'Han', 'Darth')\r\n    my_v = my_tuple.pop(0)  # AttributeError: 'tuple' object has no attribute 'pop'\r\n    for x in my_v:\r\n        print(x, end=' ')<\/pre>\n<p>A.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Tuples are ordered and unchangeable (immutable) collections of data. They can be thought of as immutable lists. They are written in round brackets:<\/p>\n","protected":false},"author":2,"featured_media":5803,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5799"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=5799"}],"version-history":[{"count":14,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5799\/revisions"}],"predecessor-version":[{"id":6251,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5799\/revisions\/6251"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media\/5803"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=5799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=5799"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=5799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}