Python: whtas the differnce betwen xrange and range?
georgegerdes (4)

I sa people talking bout xrange or range, and I wanted to know, what is th differnce? Can you use both?

You are viewing a single comment. View All
enigma_dev (92)

Hey georg, didn't we talk 2 minutes ago? anyway, here is what i found out for you:
range() and xrange() are two functions that could be used to iterate a certain number of times in for loops in Python. In Python 3, there is no xrange , but the range function behaves like xrange in Python 2.If you want to write code that will run on both Python 2 and Python 3, you should use range().

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“.

i hope that helps you! Here is a link with more info about it:
https://www.geeksforgeeks.org/range-vs-xrange-python/

georgegerdes (4)

@enigma_dev ok, that sems understandable. Thx!