What is xrange?

Brian Blais bblais at bryant.edu
Sat Jul 30 12:23:45 CEST 2011


On Jul 29, 2011, at 9:22 PM, Steven D'Aprano wrote:

> Billy Mays wrote:
> 
>> Is xrange not a generator?  I know it doesn't return a tuple or list, so
>> what exactly is it?  
> 
> xrange pre-dates generators by approximately forever. It returns a
> special "xrange object", which generates values suitable for use in
> for-loops using the old __getitem__ protocol.
> 

interesting...I never really thought about this.  Is there a reason that it wasn't reimplemented when generators came out?  Is there a use-case for the current implementation that wouldn't work as a generator?


				bb
-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/






More information about the Python-list mailing list