On Wed, Sep 15, 2010 at 10:09 AM, raymond.hettinger <python-checkins at python.org> wrote: > +The formal syntax makes no special provision for negative indices in > +sequences; however, built-in sequences all provide a :meth:`__getitem__` > +method that interprets negative indices by adding the length of the sequence > +to the index (so that ``x[-1]`` selects the last item of ``x``). The > +resulting value must be a nonnegative integer less than the number of items in > +the sequence, and the subscription selects the item whose index is that value > +(counting from zero). Since the support for negative indices and slicing > +occurs in the object's :meth:`__getitem__` method, subclasses overriding > +this method will need to explicitly add that support. Perhaps mention the slice.indices(len) helper for performing the standard conversion from negative indices to positive ones when dealing with negative indices *in* slices? Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4