diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2010-12-03 14:26:13 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2010-12-03 14:26:13 (GMT) |
commit | 37ee850b1073f3b8e85855ed02d5dc3d11c5fe62 (patch) | |
tree | f8ec863a8239f5a298951f529ed2b18cdccdc0aa /Doc | |
parent | fad058f0caca689fffad29617d0858caa13291ad (diff) | |
download | cpython-37ee850b1073f3b8e85855ed02d5dc3d11c5fe62.zip cpython-37ee850b1073f3b8e85855ed02d5dc3d11c5fe62.tar.gz cpython-37ee850b1073f3b8e85855ed02d5dc3d11c5fe62.tar.bz2 |
Issue 2690: Add support for slicing and negative indices to range objects (includes precalculation and storage of the range length).
Refer to the tracker issue for the language moratorium implications of this change
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/functions.rst | 27 | ||||
-rw-r--r-- | Doc/whatsnew/3.2.rst | 4 |
2 files changed, 30 insertions, 1 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index d6df5ba..bb392fc 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1023,8 +1023,33 @@ are always available. They are listed here in alphabetical order. >>> list(range(1, 0)) [] + Range objects implement the :class:`collections.Sequence` ABC, and provide + features such as containment tests, element index lookup, slicing and + support for negative indices: + + >>> r = range(0, 20, 2) + >>> r + range(0, 20, 2) + >>> 11 in r + False + >>> 10 in r + True + >>> r.index(10) + 5 + >>> r[5] + 10 + >>> r[:5] + range(0, 10, 2) + >>> r[-1] + 18 + + Ranges containing absolute values larger than ``sys.maxint`` are permitted + but some features (such as :func:`len`) will raise :exc:`OverflowError`. + .. versionchanged:: 3.2 - Testing integers for membership takes constant time instead of iterating + Implement the Sequence ABC + Support slicing and negative indices + Test integers for membership in constant time instead of iterating through all items. diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index 1083979..db88e4a 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -313,6 +313,10 @@ Some smaller changes made to the core Python language are: (Added by Antoine Pitrou, :issue:`10093`.) +.. XXX: Issues #9213 and #2690 make the objects returned by range() + more sequence like in accordance with their registration as + implementing the Sequence ABC + New, Improved, and Deprecated Modules ===================================== |