0 votes
in Python by
What is the difference between range and xrange?

1 Answer

0 votes
by

These both the methods are mainly used in Python to iterate the for loop for a fixed number of times. They differ only when we talk regarding Python versions.

The difference between range and xrange are as follows:

Range() method Xrange() method

The xrange() method is not supported in Python3 so that the range() method is used for iteration in for loops. The xrange() method is used only in the Python version 2 for the iteration in for loops.

List is returned by this range() method It only returns the generator object because it doesn’t produce a static list during run time.

It occupies a huge amount of memory as it stores the complete list of iterating numbers in memory. It occupies less memory because it only stores one number at the time in memory.

Related questions

0 votes
asked Jan 3 in Python by DavidAnderson
0 votes
asked Jun 24, 2020 in Python by Robindeniel
...