What is the difference between range() and xrange() in Python?

101 views

What is the difference between range() and xrange() in Python?

What is the difference between range() and xrange() in Python?

solveurit24@gmail.com Changed status to publish February 13, 2025
0
  • range() (Python 3):
    • Returns an immutable sequence object.
    • Uses less memory for large ranges by generating numbers on the fly.
  • range() (Python 2):
    • Returns a list of integers.
  • xrange() (Python 2):
    • Returns an iterator that generates numbers on the fly (memory efficient).

Note:

In Python 3, xrange() was removed, and range() behaves like xrange() in Python 2.

solveurit24@gmail.com Changed status to publish February 13, 2025
0
You are viewing 1 out of 1 answers, click here to view all answers.