using range() in for loops

Georg Brandl g.brandl-nospam at gmx.net
Wed Apr 5 11:20:52 EDT 2006


Steven D'Aprano wrote:
> On Wed, 05 Apr 2006 16:21:02 +0200, Georg Brandl wrote:
> 
>> Because of backwards compatibility. range() returns a list, xrange() an
>> iterator: list(xrange(...)) will give the same results as range(...).
> 
> Georg is pretty much correct in his explanation, but just to dot all the
> I's and cross all the T's, we should explain that xrange() doesn't return
> an iterator, it returns a special xrange object:

Ah yes, the old iterator <-> iterable problem ;)

Georg



More information about the Python-list mailing list