Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is xrange?
#4
xrange() is built-in function that returns xrange object, i.e. it will produce the same sequence as range(), but without storing all of the elements in the memory. for short one it's the same, difference comes with large sequence. you can iterate over it yielding one number at a time or pass it as argument 'everywhere where iterator is expected
As Larz60+ said in python3 it become range.
>>> for n in xrange(5):
...     print n
... 
0
1
2
3
4
>>> list(xrange(3))
[0, 1, 2]
>>> [n**2 for n in xrange(4)]
[0, 1, 4, 9]
the docs are more or less clear
Reply


Messages In This Thread
What is xrange? - by failedSIGNAL - May-30-2017, 01:50 AM
RE: [SMALL QUESTIONS] - by Larz60+ - May-30-2017, 03:21 AM
RE: [SMALL QUESTIONS] - by failedSIGNAL - May-30-2017, 04:21 AM
RE: [SMALL QUESTIONS] - by buran - May-30-2017, 05:10 AM
RE: What is xrange? - by Ofnuts - Jun-01-2017, 09:50 AM
RE: What is xrange? - by ackmondual - Jun-13-2017, 11:27 PM
RE: What is xrange? - by nilamo - Jul-06-2017, 08:27 PM
RE: What is xrange? - by DeaD_EyE - Jul-07-2017, 09:22 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020