Python array[0:1] not the same as array[0]
<p>I'm using Python to split a string of 2 bytes <code>b'\x01\x00'</code>. The string of bytes is stored in a variable called <code>flags</code>.</p>

<p>Why when I say <code>flags[0]</code> do I get <code>b'\x00'</code> but when I say <code>flags[0:1]</code> I get the expected answer of <code>b'\x01'</code>.</p>

<p>Should both of these operations not be exactly the same?</p>

<p>What I did:</p>

<pre><code>&gt;&gt;&gt; flags = b'\x01\x00'
&gt;&gt;&gt; flags[0:1]
b'\x01'
&gt;&gt;&gt; bytes(flags[0])
b'\x00'
</code></pre>

<p>Yes, you should get the same thing. In both cases <code>b'\x01'</code>. <code>flags</code> is probably not what you think it is.</p>

<pre><code>&gt;&gt;&gt; flags = b'\x01\x00'
&gt;&gt;&gt; flags[0]
'\x01'
&gt;&gt;&gt; flags[0:1]
'\x01'
</code></pre>

python python-3.x indexing bytestring