4
Reply

What is the difference between range & xrange?

    range() – This returns a list of numbers created using range() function. xrange() – This function returns the generator object that can be used to display numbers only by looping. Only particular range is displayed on demand and hence called “lazy evaluation“.Both are implemented in different ways and have different characteristics associated with them. The points of comparisons are: - Return Type - Memory - Operation Usage - Speedrange() returns – the list as return type. xrange() returns – xrange() object.

    Thanks for publishing such good questions. I also came across a platform which is also good .

    I think this is a really clear explanation of the difference between range() and xrange(), especially the part about lazy evaluation and memory usage. I remember being confused about why xrange() existed in older Python versions until I learned how much more efficient it could be for large loops. Learning programming concepts like this always makes me appreciate how many systems run behind the scenes in games and platforms, including fun projects like EaglerCraft Game.

    In Python 3, the original range function has been removed and renamed xrange to range.

    range function returns a list of numbers created using range()