

{"id":123225,"date":"2023-11-02T15:18:59","date_gmt":"2023-11-02T09:48:59","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=123225"},"modified":"2024-02-28T11:20:24","modified_gmt":"2024-02-28T05:50:24","slug":"python-program-on-tuples","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/","title":{"rendered":"Python Program on Tuples"},"content":{"rendered":"<p>In this article, we will explore a Python program that involves tuples and lists, two essential data structures in Python. The program aims to showcase the creation and manipulation of a tuple, followed by the conversion of its elements into a list. This practical example will provide insights into the characteristics and versatility of tuples and lists in Python.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>Basic understanding of tuples and lists in Python.<\/li>\n<li>Familiarity with loops and user input handling in Python.<\/li>\n<li>Knowledge of the concepts of mutability and immutability in data structures.<\/li>\n<\/ul>\n<h3>Topic Explanation<\/h3>\n<p>The program not only demonstrates the transformation of a tuple into a list but also underscores the intricacies of managing data structures with varying mutability in Python. By utilizing user input within a loop, the example goes beyond a mere conversion, providing practical insights into the dynamic interaction between tuples and lists. This dynamic interaction sheds light on how Python developers can navigate and leverage these data structures effectively, showcasing the adaptability required when dealing with both immutable and mutable elements in a single program.<\/p>\n<p>Furthermore, the example raises awareness about the potential consequences of reassigning a tuple with a list. While the reassignment may not yield the expected outcome due to the immutable nature of tuples, it serves as a learning point for developers, emphasizing the importance of understanding the fundamental characteristics of data structures for precise and effective coding practices.<\/p>\n<h4>Example<\/h4>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Define a tuple 'myt' with some initial values.\r\nmyt = (10, 20, 30, 10, 50, 10, 20, 10, 70)\r\n\r\n# Print the tuple to the console.\r\nprint(myt)\r\n\r\n# Create an empty list 'mylist' to store user-input values.\r\nmylist = []\r\n\r\n# Iterate 10 times to collect user input and append it to 'mylist'.\r\nfor i in range(10):\r\n    # Prompt the user to enter a value and store it in variable 'x'.\r\n    x = input()\r\n    \r\n    # Append the user input to the 'mylist'.\r\n    mylist.append(x)\r\n    \r\n    # Update the 'myt' tuple with the entire 'mylist'.\r\n    # Note: This reassignment might not have the intended effect as it overwrites the original tuple.\r\n    myt = (mylist)\r\nprint(myt)<\/pre>\n<p><strong>Input:<\/strong><br \/>\napple<br \/>\nbanana<br \/>\nCherry<br \/>\n10<br \/>\n20<br \/>\n30<br \/>\n40<br \/>\n50<br \/>\n60<br \/>\n70<\/p>\n<div class=\"df-code-out\">\n<p><strong>Output:<\/strong><\/p>\n<p>(10, 20, 30, 10, 50, 10, 20, 10, 70)<br \/>\n(&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;cherry&#8217;, &#8217;10&#8217;, &#8217;20&#8217;, &#8217;30&#8217;, &#8217;40&#8217;, &#8217;50&#8217;, &#8217;60&#8217;, &#8217;70&#8217;)<\/p>\n<h4>Code Explanation:<\/h4>\n<ul>\n<li>myt is defined as a tuple with elements: 10, 20, 30, 10, 50, 10, 20, 10, 70<\/li>\n<li>print(myt) prints out the tuple myt<\/li>\n<li>mylist is defined as an empty list using []<\/li>\n<li>A for loop runs 10 times (range(10))<\/li>\n<li>In each iteration, x takes input from user<\/li>\n<li>Append x to mylist using mylist.append(x)<\/li>\n<li>myt is redefined to contain the list mylist. This typecasts mylist to a tuple.<\/li>\n<\/ul>\n<h3>Summary<\/h3>\n<p>In conclusion, the Python program showcased the practical differences between tuples and lists. It demonstrated the immutability of tuples and the mutability of lists by converting a tuple into a list through user input. This example provides valuable insights for developers on effectively working with these data structures in Python, highlighting when to use each based on their inherent properties. A basic understanding of tuples, lists, loops, and user input in Python is essential for comprehending and implementing the concepts presented in the program.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will explore a Python program that involves tuples and lists, two essential data structures in Python. The program aims to showcase the creation and manipulation of a tuple, followed by&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[10333,28626,28639,10901,14984],"class_list":["post-123225","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-python-practical","tag-python-program-on-tuples","tag-python-tuples","tag-tuples-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Program on Tuples - DataFlair<\/title>\n<meta name=\"description\" content=\"The program aims to showcase the creation and manipulation of a tuple, followed by the conversion of its elements into a list.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program on Tuples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"The program aims to showcase the creation and manipulation of a tuple, followed by the conversion of its elements into a list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-02T09:48:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T05:50:24+00:00\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Program on Tuples - DataFlair","description":"The program aims to showcase the creation and manipulation of a tuple, followed by the conversion of its elements into a list.","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:\/\/data-flair.training\/blogs\/python-program-on-tuples\/","og_locale":"en_US","og_type":"article","og_title":"Python Program on Tuples - DataFlair","og_description":"The program aims to showcase the creation and manipulation of a tuple, followed by the conversion of its elements into a list.","og_url":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-11-02T09:48:59+00:00","article_modified_time":"2024-02-28T05:50:24+00:00","author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Python Program on Tuples","datePublished":"2023-11-02T09:48:59+00:00","dateModified":"2024-02-28T05:50:24+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/"},"wordCount":392,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"keywords":["Python","python practical","python program on tuples","python tuples","Tuples in python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/","url":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/","name":"Python Program on Tuples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"datePublished":"2023-11-02T09:48:59+00:00","dateModified":"2024-02-28T05:50:24+00:00","description":"The program aims to showcase the creation and manipulation of a tuple, followed by the conversion of its elements into a list.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-program-on-tuples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Program on Tuples"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=123225"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123225\/revisions"}],"predecessor-version":[{"id":134115,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/123225\/revisions\/134115"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=123225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=123225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=123225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}