[Python-ideas] [Python-Dev] Inclusive Range

C. Titus Brown ctb at msu.edu
Tue Oct 5 15:13:56 CEST 2010


On Tue, Oct 05, 2010 at 02:07:41PM +0100, Michael Foord wrote:
> On 5 October 2010 12:51, Carl M. Johnson <cmjohnson.mailinglist at gmail.com>wrote:
> 
> > [snip...]
> >
> > Yup. TANSTAAFL. That's why we shouldn't actually bother to change
> > things: you lose on the backend what you gain on the frontend. I'm
> > just curious about whether starting programmers have a strong
> > preference for one or the other convention or whether both are
> > confusing.
> 
> Both teaching new programmers and programmers coming from other languages
> I've found them confused by the range behaviour and usually end up having to
> apologise for it (a sure sign of a language wart).
> 
> It is *good* that range(5) produces 5 values (0 to 4) but *weird* that
> range(3, 10) doesn't include the 10.
> 
> Changing it now would be *very* backwards incompatible of course. Python 4
> perhaps?

Doesn't it make sense that 

len(range(5)) == 5

and

for i in range(5):
   ...

mimics the C/C++ behavior of

   for (i = 0; i < 5; i++) ...

?

--titus
-- 
C. Titus Brown, ctb at msu.edu



More information about the Python-ideas mailing list