Difference between range and xrange?



Satish Said

+0 -0

range: (Python 2 and 3) Creates an entire list in memory at once, faster for repeated iteration but can consume significant memory with large sequences.
xrange: (Python 2 only) Generates numbers on demand, saving memory for big ranges but slower for multiple iterations and lacks list-like operations.



Submit Your Response