Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32779 > unrolled thread

Re: Difference between range and xrange ??

Started byTerry Reedy <tjreedy@udel.edu>
First post2012-11-05 13:38 -0500
Last post2012-11-05 13:38 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Difference between range and xrange ?? Terry Reedy <tjreedy@udel.edu> - 2012-11-05 13:38 -0500

#32779 — Re: Difference between range and xrange ??

FromTerry Reedy <tjreedy@udel.edu>
Date2012-11-05 13:38 -0500
SubjectRe: Difference between range and xrange ??
Message-ID<mailman.3294.1352140702.27098.python-list@python.org>
On 11/5/2012 9:23 AM, inshu chauhan wrote:
> what is the difference between range and xrange.. both seem to work the
> same. ?

 >>> range(3)
[0, 1, 2]
 >>> xrange(3)
xrange(3)

You should read the appropriate manual entries before asking trivial 
questions. They say pretty clearly that range returns a list and xrange 
an xrange object.
http://docs.python.org/2/library/functions.html#range
http://docs.python.org/2/library/functions.html#xrange

If you do not understand the entries, quote the part that confuses you 
and say what you are unclear about.

> And which should be used where and in what situations.. ??

The entry for xrange (added after range) tries to explain this. It is 
for situations in which one does not want a list, but only the sequence 
of numbers, especially in situations where the length of the list would 
be large enough to make creating the unneeded list a nuisance.


-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web