However, the second case will be usually formatted as x = +3, as per
PEP 8
So unless PEP8 is updated to require/suggest spaces around a keyword index (which I'm not proposing), then I am -1 for the suggested feature, at least when the initial element is missing.
PEP8 can't require, and of course it could be updated -- that seems a non issue.
As for "why not" not being a motivator -- I agree, I posted it that easy because this conversation has brought up a number of examples where slice syntax is nice to use. And David Mertz pointed out, both numpy and pandas have a utility to make easier slices -- yes, that's an argument for why you don't need them, but it's also an argument for why there IS a need for slice objects outside of the square brackets, and if we need slice objects, then slice syntax is nice.
But rather than suggesting one or two places where we might use sloce syntax: e.g. function calls:
object.get_subset(x=a:b, y=c:d), or itertools,islice(it, 2:20:2)
Once you allow them anywhere outside [], then the question does become "why not?", because having an expression that is only valid in some small fraction of contexts gets even more confusing.
Of course, as has been pointed out here -- dict displays are one good reason NOT to support it.
Which is too bad -- I'd really like to see it more broadly available -- I think it's a very nice syntax.
I am strongly in favor of having slices. The main motivating factor for me, labelled dimensions in xarray, would be much, much less useful without support for slices. In fact, as PEP 472 currently mentions, the big benefit of indexing over method calls is that indexing supports slice syntax while method calls don't.
so maybe the solution is to have method calls support slices :-)
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IQJNOQS2LKHWSSYAJX7KDNWJ5ZFZ25N4/
Code of Conduct: http://python.org/psf/codeofconduct/