String representation of xrange return keyword with value. foo = xrange(5) print foo >>> xrange(5) foo.__str__() >>> xrange(5) I think, that expected result should be somethink like this: >>> <xrange object at 0x00AFB970>
For types where it's possible, the str or repr returns a string that can be passed to eval: >>> for i in eval(str(xrange(5))): ... print i ... 0 1 2 3 4 xrange (and list, and tuple, and others) fall into this category.