<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tuple | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/tuple/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Wed, 28 Sep 2022 16:33:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Tuple</title>
		<link>https://studentprojects.in/software-development/tuple/</link>
					<comments>https://studentprojects.in/software-development/tuple/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Wed, 28 Sep 2022 16:33:21 +0000</pubDate>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tuple]]></category>
		<category><![CDATA[Removing tuple]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=9578</guid>

					<description><![CDATA[<p>In Python, a tuple is an immutable data type. In Python, a tuple is a group of components surrounded in (). (parentheses). Once defined, a tuple cannot be amended; that is, neither its components nor its values can be changed. Tuples in Python : a=()&#160;&#160;&#160; # It&#8217;s an example of empty tuple x=(1,)&#160;&#160; # Tuple</p>
<p>The post <a href="https://studentprojects.in/software-development/tuple/">Tuple</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In Python, a tuple is an immutable data type. In Python, a tuple is a group of components surrounded in (). (parentheses). Once defined, a tuple cannot be amended; that is, neither its components nor its values can be changed.</p>



<p>Tuples in Python :</p>



<p>a=()&nbsp;&nbsp;&nbsp; # It&#8217;s an example of empty tuple</p>



<p>x=(1,)&nbsp;&nbsp; # Tuple with single value i.e. 1</p>



<p>tup1 = (1,2,3,4,5)</p>



<p>tup1 = (&#8216;harry&#8217;, 5, &#8216;demo&#8217;, 5.8)</p>



<p>When generating tuples of a single element, it is necessary to use a comma (&#8216;,&#8217;) after that element, like in the example below: tup=(1,) because the Python interpreter will treat it as a single entity if there is only one element inside the parenthesis.</p>



<p>Getting Values out of Tuples</p>



<p>Use the square brackets for slicing along with the index or indices to obtain the value located at that index to access values in tuples.</p>



<p>!/usr/bin/python</p>



<p>tup1 = (&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000);</p>



<p>tup2 = (1, 2, 3, 4, 5, 6, 7 );</p>



<p>print &#8220;tup1[0]: &#8220;, tup1[0];</p>



<p>print &#8220;tup2[1:5]: &#8220;, tup2[1:5];</p>



<p>When the above code is executed, it produces the following result −</p>



<p>tup1[0]:&nbsp; physics</p>



<p>tup2[1:5]:&nbsp; [2, 3, 4, 5]</p>



<p>Tuple updates</p>



<p>Due to their immutability, tuples cannot be updated or have their element values changed. The example that follows explains how you can combine pieces of already-existing tuples to generate new tuples.</p>



<p>#!/usr/bin/python</p>



<p>tup1 = (12, 34.56);</p>



<p>tup2 = (&#8216;abc&#8217;, &#8216;xyz&#8217;);</p>



<p># Following action is not valid for tuples</p>



<p># tup1[0] = 100;</p>



<p># So let&#8217;s create a new tuple as follows</p>



<p>tup3 = tup1 + tup2;</p>



<p>print tup3;</p>



<p>When the above code is executed, it produces the following result −</p>



<p>(12, 34.56, &#8216;abc&#8217;, &#8216;xyz&#8217;)</p>



<p>Removing tuple elements</p>



<p>Individual tuple elements cannot be eliminated. Naturally, there is nothing wrong with creating another tuple after eliminating the undesirable components. Use the del statement to specifically remove a whole tuple.</p>



<p>For example −</p>



<p>#!/usr/bin/python</p>



<p>tup = (&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000);</p>



<p>print tup;</p>



<p>del tup;</p>



<p>print &#8220;After deleting tup : &#8220;;</p>



<p>print tup;</p>



<p>This produces the following result. Note an exception raised, this is because after del tup tuple does not exist any more −</p>



<p>(&#8216;physics&#8217;, &#8216;chemistry&#8217;, 1997, 2000)</p>



<p>After deleting tup :</p>



<p>Traceback (most recent call last):</p>



<p>&nbsp;&nbsp; File &#8220;test.py&#8221;, line 9, in &lt;module&gt;</p>



<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print tup;</p>



<p>NameError: name &#8216;tup&#8217; is not defined</p><p>The post <a href="https://studentprojects.in/software-development/tuple/">Tuple</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/tuple/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
