[Python-Dev] range objects in 3.x

Ethan Furman ethan at stoneleaf.us
Fri Sep 23 22:38:08 CEST 2011


Benjamin Peterson wrote:
> 2011/9/23 Ethan Furman <ethan at stoneleaf.us>:
>> Benjamin Peterson wrote:
>>> 2011/9/23 Ethan Furman <ethan at stoneleaf.us>:
>>>>
>>>> Follow-up question: since the original range returned lists, and
>>>> comparisons
>>>> do make sense for lists, should the new range also implement them?
>>> What would be the use-case?
>> The only reason I'm aware of at the moment is to prevent loss of
>> functionality from 2.x range to 3.x range.
> 
> range comparisons in 2.x have no functionality.

Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
--> r1 = range(10)
--> r2 = range(0, 20, 2)
--> r3 = range(10)
--> r1 == r3
True
--> r1 < r2
True
--> r3 > r2
False

Yes, I realize this is because range returned a list in 2.x.  However, 
aren't __contains__, __getitem__, count, and index implemented in 3.x 
range because 2.x range returned lists?

~Ethan~


More information about the Python-Dev mailing list