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

Masklinn masklinn at masklinn.net
Tue Oct 5 17:03:11 CEST 2010


On 2010-10-05, at 16:51 , Michael Foord wrote:
> On 05/10/2010 15:33, Alexander Belopolsky wrote:
>> On Tue, Oct 5, 2010 at 9:16 AM, Michael Foord<fuzzyman at voidspace.org.uk>  wrote:
>>> ... 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.
>> Teach them about range(x, y, z) and once you cover negative z they
>> will stop complaining about range(x, y). :-)
> 
> Well, it probably doesn't help (for those coming to Python from languages other than C) that some languages do-the-right-thing with ranges. <0.5 wink>
> 
> $ irb
> >> (1..3).to_a
> => [1, 2, 3]
> 
> All the best,
True, likewise for Haskell:
Prelude> [0..5]
[0,1,2,3,4,5]

On the other hand (for Ruby),
>> (1...3).to_a
=> [1, 2]

Ruby is also a bit different in that ranges are generally used more for containment-testing (via when) and there is a separate Fixnum.upto for iteration.


More information about the Python-ideas mailing list