list (range) syntax

Carl Banks pavlovevidence at
Thu Oct 25 04:35:59 CEST 2007

On Oct 24, 6:44 pm, Michal Bozon <boz... at> wrote:
> many Python newcomers are confused why
> range(10), does not include 10.
> If there was a proposal for the new
> syntax for ranges, which is known
> e.g. from Pascal or Ruby...
> >>> [0..10]
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> there a chance to be approved ?
> We have had a short discussion on it
> at the irc, I hope that the fact
> that nobody agreed it is a good idea
> was just an accident :)

No, sorry, it's just not going to happen.

In fact, the opposite is happening.  Python is removing the few cases
that use a closed interval.  For example, random.randint(a,b), which
returned a random integer in range a to b inclusive, was deprecated in
favor of random.randrange(a,b), which generates a random integer in
range a to b, not inclusive.

The advantages of open ranges are especially apparent to someone like
me, who uses Python at home, then has to go to work and Matlab.  It's
not that I accidentally use open intervals a lot (I've gotten into the
habit of making sure I am using closed intervals whenever my tension
level is high :), but all the extra "+1"s and "-1"s that I need when
splicing arrays gets pretty old.

Carl Banks

More information about the Python-list mailing list