Problem with Python xrange

r holland rhh at structurelabs.com
Mon Jun 7 00:55:56 CEST 2004


xrange is a special object intended for operations like looping

try this: 

a=xrange(10)
b=range(10)

if you do:

type(a)
type(b)
you'll see that a is 'xrange' and b is a 'list'


if you do:
dir(a)
dir(b)

you'll see that a has all of the list methods (which includes slicing)
whereas b has none.  

xrange is a generator object so slicing is not relevant, although
you could assemble a list from the generator using append,
that could then be sliced.



More information about the Python-list mailing list