On Sun, Feb 1, 2015 at 10:13 AM, Todd <toddrjen@gmail.com> wrote:

Although slices and ranges are used for different things and implemented differently, conceptually they are similar: they define an integer sequence with a start, stop, and step size.  For this reason I think that slices could provide useful syntactic sugar for defining ranges without sacrificing clarity.

The syntax I propose is simply to wrap a slice in parentheses.  For examples, the following pairs are equivalent:

range(4, 10, 2)

range(3, 7)


This syntax should not be easily confused with any existing syntax.  Slices of sequences use square brackets, dictionaries use curly braces, and function annotations only appear in function declarations.  It is also considerably more compact than the current range syntax, while still being similar to a syntax (slicing) all python users should be familiar with.

It may be too late for this, but I like it. We can also elide extra parentheses inside calls, like with generator expressions:

Also, using list comprehension to generator expression analogy, we can have
which produces a list instead of a range object. Other than for completeness this does not seem very useful, though.