Negative array indicies and slice()
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Oct 29 18:14:41 EDT 2012
On Mon, 29 Oct 2012 11:19:38 +0000, Steven D'Aprano wrote:
> Because xrange represents a concrete sequence of numbers, all three of
> start, end and stride must be concrete, known, integers:
>
> py> xrange(4, None, 2)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: an integer is required
>
> Whereas slices can trivially include blanks that get filled in only when
> actually used:
>
> py> "hello world"[aslice]
> 'owrd'
> py> "NOBODY expects the Spanish Inquisition!"[aslice]
> 'D xet h pns nusto!'
/me facepalms/
Argggh, I forgot to copy-and-paste the critical line defining aslice:
aslice = slice(4, None, 2)
Sorry about that.
--
Steven
More information about the Python-list
mailing list