A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-September/103657.html below:

[Python-Dev] [Python-checkins] r84823 - python/branches/py3k/Doc/reference/expressions.rst

[Python-Dev] [Python-checkins] r84823 - python/branches/py3k/Doc/reference/expressions.rst [Python-Dev] [Python-checkins] r84823 - python/branches/py3k/Doc/reference/expressions.rstNick Coghlan ncoghlan at gmail.com
Wed Sep 15 15:28:20 CEST 2010
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
More information about the Python-Dev mailing list

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