Retrieve length of slice from slice object in Python : <p>The title explains itself, how to get 2 out of the object</p>

<pre><code>slice(0,2)
</code></pre>

<p>The documentation is somewhat confusing, or it is the wrong one</p>

<p><a href="https://docs.python.org/2/c-api/slice.html" rel="noreferrer">https://docs.python.org/2/c-api/slice.html</a></p>

<p>In particular I don't understand what is the meaning of the output of</p>

<pre><code>slice(0,2).indices(0)  # (0, 0, 1)
slice(0,2).indices(10 ** 10)  # (0, 2, 1)
</code></pre>

<p>One possible workaround is to slice a list with the slice object</p>

<pre><code>a = [1,2,3,4,5]
len(a[slice(0,2)])  # 2
</code></pre>

<p>But this will fail for an arbitrary large slice.</p>

<p>Thanks, I couldn't find an answer In other posts. </p>
