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

Masklinn masklinn at masklinn.net
Tue Oct 5 16:47:33 CEST 2010

On 2010-10-05, at 16: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). :-)
> At least you don't have to deal with range vs. xrange in 3.x anymore.
> IMO, range([start,] stop[, step]) is one of the worst interfaces in
> python.  Is there any other function with an optional *first*
> argument?
Dict, kinda, though the other arguments are keywords so it probably doesn't count.

>  Why range(date(2010, 1, 1), date(2010, 2, 1), timedelta(1))
> cannot be used to produce days in January?
Likewise for range('a', 'e'). Range only working on integers is definitely annoying compared to the equivalent construct in Haskell for instance, or Ruby (though ruby has the issue of indistinguishable half-closed and fully-closed ranges when using the operator version).

>  Why range(2**300)
> succeeds, but len(range(2**300)) raises OverflowError?
The former overflows in Python 2. It doesn't in Python 3 due to `range` being an iterable not a list.

More information about the Python-ideas mailing list