Message226191
Oooh, yes. The colon in a slice should be treated as a binary operator, with equal space before and after.
I think we can add this (as a new bullet following the bullet "Immediately before a comma, semicolon, or colon"):
- However, the colon in a slice acts like a binary operator, and
should have equal amounts on either side. In an extended slice,
both colons must have the same amount of spacing applied. ::
Yes: ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
Yes: ham[lower + offset : upper + offset], ham[lower : upper : 3]
No: ham[1: 9], ham[1 :9]
I'm not sure what to recommend for extended slices when one or several of the slots are empty; my intuition suggests that there should be no spaces around any colons in that case, but I'm not sure what to do if you really have a long expression as one slot. Which is better?
ham[lower + 1 :: step]
or
ham[lower + 1 : : step]
similar for other cases, e.g.
ham[lower + 1 : upper + 1 :]
vs.
ham[lower + 1 : upper + 1 : ]
To me, *all* of those feel weird. |
|
Date |
User |
Action |
Args |
2014-08-31 21:02:37 | gvanrossum | set | recipients:
+ gvanrossum, barry, ncoghlan, docs@python, Guido.van.Rossum, anthonymayer |
2014-08-31 21:02:37 | gvanrossum | set | messageid: <1409518957.68.0.580016983518.issue22316@psf.upfronthosting.co.za> |
2014-08-31 21:02:37 | gvanrossum | link | issue22316 messages |
2014-08-31 21:02:37 | gvanrossum | create | |
|