Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Enumerating the possibilities allowed by the grammar:</p> <pre><code>&gt;&gt;&gt; seq[:] # [seq[0], seq[1], ..., seq[-1] ] &gt;&gt;&gt; seq[low:] # [seq[low], seq[low+1], ..., seq[-1] ] &gt;&gt;&gt; seq[:high] # [seq[0], seq[1], ..., seq[high-1]] &gt;&gt;&gt; seq[low:high] # [seq[low], seq[low+1], ..., seq[high-1]] &gt;&gt;&gt; seq[::stride] # [seq[0], seq[stride], ..., seq[-1] ] &gt;&gt;&gt; seq[low::stride] # [seq[low], seq[low+stride], ..., seq[-1] ] &gt;&gt;&gt; seq[:high:stride] # [seq[0], seq[stride], ..., seq[high-1]] &gt;&gt;&gt; seq[low:high:stride] # [seq[low], seq[low+stride], ..., seq[high-1]] </code></pre> <p>Of course, if <code>(high-low)%stride != 0</code>, then the end point will be a little lower than <code>high-1</code>.</p> <p>If <code>stride</code> is negative, the ordering is changed a bit since we're counting down:</p> <pre><code>&gt;&gt;&gt; seq[::-stride] # [seq[-1], seq[-1-stride], ..., seq[0] ] &gt;&gt;&gt; seq[high::-stride] # [seq[high], seq[high-stride], ..., seq[0] ] &gt;&gt;&gt; seq[:low:-stride] # [seq[-1], seq[-1-stride], ..., seq[low+1]] &gt;&gt;&gt; seq[high:low:-stride] # [seq[high], seq[high-stride], ..., seq[low+1]] </code></pre> <p>Extended slicing (with commas and ellipses) are mostly used only by special data structures (like Numpy); the basic sequences don't support them.</p> <pre><code>&gt;&gt;&gt; class slicee: ... def __getitem__(self, item): ... return `item` ... &gt;&gt;&gt; slicee()[0, 1:2, ::5, ...] '(0, slice(1, 2, None), slice(None, None, 5), Ellipsis)' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload