[Python-ideas] More useful slices
Todd
toddrjen at gmail.com
Sun Feb 1 16:13:32 CET 2015
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)
(4:10:2)
range(3, 7)
(3:7)
range(5)
(:5)
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150201/c1bca357/attachment.html>
More information about the Python-ideas
mailing list