Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Difference between range and xrange ??

Reply
Thread Tools

Re: Difference between range and xrange ??

 
 
Terry Reedy
Guest
Posts: n/a
 
      11-05-2012
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
range() vs xrange() Python2|3 issues for performance harrismh777 Python 11 08-04-2011 09:56 AM
RE: I'm missing something here with range vs. xrange Joe Goldthwaite Python 4 12-08-2007 06:27 AM
I'm missing something here with range vs. xrange Joe Goldthwaite Python 2 12-07-2007 10:08 PM
why I don't like range/xrange stdazi Python 17 02-18-2007 01:59 PM
efficiency of range() and xrange() in for loops Steve R. Hastings Python 29 04-09-2006 08:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57