[Python-Dev] [Python-checkins] r84823 - python/branches/py3k/Doc/reference/expressions.rst (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Sep 15 15:28:20 CEST 2010
- Previous message: [Python-Dev] 2.6.6 is a release candidate?
- Next message: [Python-Dev] 3.x as the official release
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 thatx[-1]
selects the last item ofx
). 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
- Previous message: [Python-Dev] 2.6.6 is a release candidate?
- Next message: [Python-Dev] 3.x as the official release
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]