<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Tuple</id>
	<title>Tuple - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Tuple"/>
	<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Tuple&amp;action=history"/>
	<updated>2026-06-04T17:56:10Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Tuple&amp;diff=146&amp;oldid=prev</id>
		<title>Davrot: Created page with &quot; == The goal == Tuple are a non-mutable container which is typically used for heterogenic data types and is very important for functions with multiple return values.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == [https://docs.python.org/3/library/stdtypes.html#tuple​ Tuples​] == &lt;blockquote&gt;Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the enumerate() built-in). Tuples are...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Tuple&amp;diff=146&amp;oldid=prev"/>
		<updated>2025-10-15T13:13:33Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == The goal == Tuple are a non-mutable container which is typically used for heterogenic data types and is very important for functions with multiple return values.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == [https://docs.python.org/3/library/stdtypes.html#tuple​ Tuples​] == &amp;lt;blockquote&amp;gt;Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the enumerate() built-in). Tuples are...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== The goal ==&lt;br /&gt;
Tuple are a non-mutable container which is typically used for heterogenic data types and is very important for functions with multiple return values.&lt;br /&gt;
&lt;br /&gt;
Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/library/stdtypes.html#tuple​ Tuples​] ==&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Tuples are immutable sequences, typically used to store collections of heterogeneous data (such as the 2-tuples produced by the enumerate() built-in). Tuples are also used for cases where an immutable sequence of homogeneous data is needed (such as allowing storage in a set or dict instance).&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
A tuple is a list of stuff that is enclosed in &amp;#039;&amp;#039;&amp;#039;( )&amp;#039;&amp;#039;&amp;#039; and seperated by &amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039; . An optional &amp;#039;&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039; after the last element is allowed.&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    &amp;quot;b&amp;quot;,&lt;br /&gt;
    &amp;quot;c&amp;quot;,&lt;br /&gt;
)&lt;br /&gt;
print(a)&lt;br /&gt;
&lt;br /&gt;
a = (&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot;)&lt;br /&gt;
print(a)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;(&amp;#039;a&amp;#039;, &amp;#039;b&amp;#039;, &amp;#039;c&amp;#039;)&lt;br /&gt;
(&amp;#039;a&amp;#039;, &amp;#039;b&amp;#039;, &amp;#039;c&amp;#039;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Immutable ==&lt;br /&gt;
After creating a tuple cannot be modified. They are immutable.&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    &amp;quot;b&amp;quot;,&lt;br /&gt;
    &amp;quot;c&amp;quot;,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
a[0] = &amp;quot;d&amp;quot; # -&amp;gt; TypeError: &amp;#039;tuple&amp;#039; object does not support item assignment&amp;lt;/syntaxhighlight&amp;gt;But this doesn’t mean that we can not stored mutable objects in a tuple. Furthermore these mutable objects stay mutable.&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    [&amp;quot;a&amp;quot;],&lt;br /&gt;
    &amp;quot;b&amp;quot;,&lt;br /&gt;
    &amp;quot;c&amp;quot;,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
a[0][0] = &amp;quot;d&amp;quot; # Okay, because changes the content of the list stored in a[0]&lt;br /&gt;
a[0] = &amp;quot;d&amp;quot; # -&amp;gt; TypeError: &amp;#039;tuple&amp;#039; object does not support item assignment&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Indexing ==&lt;br /&gt;
Idexing is the same as in lists.&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
print(a[0]) # -&amp;gt; a&lt;br /&gt;
print(a[1]) # -&amp;gt; 2&lt;br /&gt;
print(a[-1]) # -&amp;gt; 3.3&lt;br /&gt;
print(a[:1]) # -&amp;gt; (&amp;#039;a&amp;#039;,)&lt;br /&gt;
print(a[1:]) # -&amp;gt; (2, 3.3)&lt;br /&gt;
print(a[::2]) # -&amp;gt; (&amp;#039;a&amp;#039;, 3.3)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== * ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
print(a*3)&lt;br /&gt;
print(3*a)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;(&amp;#039;a&amp;#039;, 2, 3.3, &amp;#039;a&amp;#039;, 2, 3.3, &amp;#039;a&amp;#039;, 2, 3.3)&lt;br /&gt;
(&amp;#039;a&amp;#039;, 2, 3.3, &amp;#039;a&amp;#039;, 2, 3.3, &amp;#039;a&amp;#039;, 2, 3.3)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== len() ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
print(len(a)) # -&amp;gt; 3&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== + ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
b = (&lt;br /&gt;
    &amp;quot;b&amp;quot;,&lt;br /&gt;
    8.8,&lt;br /&gt;
    5,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
print(a+b) # -&amp;gt; (&amp;#039;a&amp;#039;, 2, 3.3, &amp;#039;b&amp;#039;, 8.8, 5)&lt;br /&gt;
print(b+a) # -&amp;gt; (&amp;#039;b&amp;#039;, 8.8, 5, &amp;#039;a&amp;#039;, 2, 3.3)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== in ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(2 in a) # -&amp;gt; True&lt;br /&gt;
print(2 not in a) # -&amp;gt; False&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== index() ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(a.index(2)) # -&amp;gt; 1 &lt;br /&gt;
print(a.index(&amp;quot;a&amp;quot;)) # -&amp;gt; 0&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== count() ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    2,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(a.count(2)) # -&amp;gt; 3&lt;br /&gt;
print(a.count(&amp;quot;a&amp;quot;)) # -&amp;gt; 2 &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== min() and max() ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    9,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
    22,&lt;br /&gt;
    2,&lt;br /&gt;
    2,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
print(min(a)) # -&amp;gt; 2&lt;br /&gt;
print(max(a)) # -&amp;gt; 22&amp;lt;/syntaxhighlight&amp;gt;Strings are not allowed&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;a = (&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    3.3,&lt;br /&gt;
    &amp;quot;a&amp;quot;,&lt;br /&gt;
    2,&lt;br /&gt;
    2,&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
print(min(a))&lt;br /&gt;
print(max(a))&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;TypeError: &amp;#039;&amp;lt;&amp;#039; not supported between instances of &amp;#039;int&amp;#039; and &amp;#039;str&amp;#039;&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range​ Common Sequence Operations] ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Operation&lt;br /&gt;
!Result&lt;br /&gt;
|-&lt;br /&gt;
|x in s&lt;br /&gt;
|True if an item of s is equal to x, else False&lt;br /&gt;
|-&lt;br /&gt;
|x not in s&lt;br /&gt;
|False if an item of s is equal to x, else True&lt;br /&gt;
|-&lt;br /&gt;
|s + t&lt;br /&gt;
|the concatenation of s and t&lt;br /&gt;
|-&lt;br /&gt;
|s * n or n * s&lt;br /&gt;
|equivalent to adding s to itself n times&lt;br /&gt;
|-&lt;br /&gt;
|s[i]&lt;br /&gt;
|ith item of s, origin 0&lt;br /&gt;
|-&lt;br /&gt;
|s[i:j]&lt;br /&gt;
|slice of s from i to j&lt;br /&gt;
|-&lt;br /&gt;
|s[i:j:k]&lt;br /&gt;
|slice of s from i to j with step k&lt;br /&gt;
|-&lt;br /&gt;
|len(s)&lt;br /&gt;
|length of s&lt;br /&gt;
|-&lt;br /&gt;
|min(s)&lt;br /&gt;
|smallest item of s&lt;br /&gt;
|-&lt;br /&gt;
|max(s)&lt;br /&gt;
|largest item of s&lt;br /&gt;
|-&lt;br /&gt;
|s.index(x[, i[, j]])&lt;br /&gt;
|index of the first occurrence of x in s (at or after index i and before index j)&lt;br /&gt;
|-&lt;br /&gt;
|s.count(x)&lt;br /&gt;
|total number of occurrences of x in s&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
</feed>