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><code>string</code> is not a type of <code>tuple</code>. Infact both belongs to different class. How <code>in</code> statement will be evaluated is based on the <code>__contains__()</code> magic function defined within there respective class.</p>

<p>Read <a href="http://stackoverflow.com/questions/14766767/how-do-you-set-up-the-contains-method-in-python">How do you set up the contains method in python</a>, may be you will find it useful. To know about magic functions in Python, read: <a href="http://www.rafekettler.com/magicmethods.html">A Guide to Python's Magic Methods</a></p>

python string tuples