I wonder what is the difference between the range() and the xrange() functions in python. I have seen them used equally many times.
Asked
Active
Viewed 390 times
-3
-
2[Plenty of information comes up if you just google it.](https://www.google.com/search?q=python+xrange+vs+range) – user2357112 Sep 09 '17 at 23:01
1 Answers
0
In Python 2.X range() creates a list. You can assign it to a variable. But xrange() creates an object that is used for iteration. range() consumes memory for each of its elements while xrange() doesn't have elements. I've read that xrange is better to conserve memory.
They discuss this more on What is the difference between range and xrange functions in Python 2.X?

Daniel Jordán
- 11
- 1
-
You shouldn't answer questions that have been answered repeatedly. Please see [answer]. – EJoshuaS - Stand with Ukraine Sep 09 '17 at 23:06