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>Just adding to Cameron Lee's answer so that it accepts <code>inner</code> containing a single integer.</p>

<pre><code>def contains(inner, outer):
    try:
        inner_len = len(inner)
        for i, _ in enumerate(outer):
            outer_substring = outer[i:i+inner_len]
            if outer_substring == inner:
                return True
        return False
    except TypeError:
        return inner in outer

contains(4, (3,1,2,4,5))  # returns True
contains((4), (3,1,2,4,5))  # returns True
</code></pre>

python string tuples