Why does 11 not printed from a string in this Python script?
<p>There is a Python question like this:</p>

<pre><code>&gt;&gt;&gt; import string
&gt;&gt;&gt; s = âmary11had a little lambâ
&gt;&gt;&gt; print s
mary had a little lamb
</code></pre>

<p>Actually when I try it myself, the result is not that, but:</p>

<pre><code>mary11had a little lamb
</code></pre>

<p>Is there anything I don't know about Python that can make 11 disappear from a string?</p>

<p>As Padraic has pointed out in the comments - it looks like the leading backslash is missing before the 11 as a minor typo in the question.</p>

<p>So it should read </p>

<pre><code>&gt;&gt;&gt; import string
&gt;&gt;&gt; s = âmary\11had a little lambâ
&gt;&gt;&gt; print s
mary    had a little lamb
</code></pre>

<p>It's interpreting \11 as the escape sequence for a numerically defined ascii character, which in this case is horizontal tab (\t). As without qualification, <code>\nnn</code> is assumed to be octal (as opposed to <code>\xnn</code> which is interpreted as hexadecimal).</p>

<p>So if you were to write just <code>&gt;&gt;&gt; s</code> in the REPL, you'd expect it to evaluate to <code>'mary\thad a little lamb'</code>.</p>

<p>Same outcome if you entered: <code>'mary\x09had a little lamb'</code></p>

python string