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


Groups > comp.lang.python > #32779

Re: Difference between range and xrange ??

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '[0,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'entries,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:between': 0.16; 'unneeded': 0.16; 'xrange': 0.16; 'wrote:': 0.17; 'tries': 0.17; 'jan': 0.18; '>>>': 0.18; 'appropriate': 0.20; 'object.': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'creating': 0.26; 'am,': 0.27; 'entries': 0.27; 'header:X-Complaints-To:1': 0.28; 'about.': 0.29; 'questions.': 0.29; 'manual': 0.29; 'this.': 0.29; 'asking': 0.32; 'url:python': 0.32; 'to:addr:python-list': 0.33; 'entry': 0.33; 'list': 0.35; 'same.': 0.35; 'sequence': 0.35; 'especially': 0.35; 'received:org': 0.36; 'explain': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'enough': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'list,': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'range': 0.60; 'between': 0.63; 'received:fios.verizon.net': 0.84; 'unclear': 0.84; 'url:functions': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Difference between range and xrange ??
Date Mon, 05 Nov 2012 13:38:06 -0500
References <CAFqGZRGnKNsw6W-Tc+JahziuYgRXPt=mp6w5i+ecUBrNyuwSzA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0
In-Reply-To <CAFqGZRGnKNsw6W-Tc+JahziuYgRXPt=mp6w5i+ecUBrNyuwSzA@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3294.1352140702.27098.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352140702 news.xs4all.nl 6866 [2001:888:2000:d::a6]:35950
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32779

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web