5 Oct 2010 15:16
Re: [Python-Dev] Inclusive Range
On 05/10/2010 14:13, C. Titus Brown wrote: > On Tue, Oct 05, 2010 at 02:07:41PM +0100, Michael Foord wrote: >> On 5 October 2010 12:51, Carl M. Johnson<cmjohnson.mailinglist@...>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++) ... > Yes. That is why I said that the current behaviour of range for a single input is *good*. Perhaps I should have been clearer; it is only the behaviour of range(x, y) that I've found people-new-to-python confused by. All the best, Michael > ? > > --titus -- -- http://www.voidspace.org.uk/blog READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.
RSS Feed