Python newbie clarification about tuples and strings
<p>I just learned that I can check if a substring is inside a string using:</p>

<blockquote>
  <p>substring in string</p>
</blockquote>

<p>It looks to me that a string is just a special kind of tuple where its elements are chars. So I wonder if there's a straightforward way to search a slice of a tuple inside a tuple. The elements in the tuple can be of any type.</p>

<blockquote>
  <p>tupleslice in tuple</p>
</blockquote>

<p>Now my related second question:</p>

<pre><code>&gt;&gt;&gt; tu = 12 ,23, 34,56
&gt;&gt;&gt; tu[:2] in tu
False
</code></pre>

<p>I gather that I get False because (12, 23) is not an element of tu. But then, why substring in string works?. Is there syntactic sugar hidden behind scenes?.</p>

<p>Try just playing around with tuples and splices. In this case its pretty easy because your splice is essentially indexing. </p>

<pre><code>&gt;&gt;&gt; tu = 12 ,23, 34,56  
&gt;&gt;&gt; tu
(12, 23, 34, 56) #a tuple of ints
&gt;&gt;&gt; tu[:1] # a tuple with an int in it
(12,) 
&gt;&gt;&gt; tu[:1] in tu #checks for a tuple against int. no match.
False 
&gt;&gt;&gt; tu[0] in tu #checks for int against ints. matched!
True
&gt;&gt;&gt; #you can see as we iterate through the values...
&gt;&gt;&gt; for i in tu:
         print(""+str(tu[:1])+" == " + str(i))

(12,) == 12
(12,) == 23
(12,) == 34
(12,) == 56
</code></pre>

<p>Splicing is returning a list of tuples, but you need to index further to compare <code>in</code> by values and not containers. Spliced strings return values, strings and the <code>in</code> operator can compare to values, but splicing tuples returns tuples, which are containers. </p>

python string tuples