Clarify space around colon in slice (severa cases).

This commit is contained in:
Guido van Rossum 2014-08-31 20:18:33 -07:00
parent dcaa78ee96
commit d2c09a26cf
1 changed files with 23 additions and 2 deletions

View File

@ -408,6 +408,27 @@ Avoid extraneous whitespace in the following situations:
Yes: if x == 4: print x, y; x, y = y, x
No: if x == 4 : print x , y ; x , y = y , x
- However, in a slice the colon acts like a binary operator, and
should have equal amounts on either side (treating it as the
operator with the lowest priority). In an extended slice, both
colons must have the same amount of spacing applied. Exception:
when a slice parameter is omitted, the space is omitted.
Yes::
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
ham[lower+offset : upper+offset]
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
ham[lower + offset : upper + offset]
No::
ham[lower + offset:upper + offset]
ham[1: 9], ham[1 :9], ham[1:9 :3]
ham[lower : : upper]
ham[ : upper]
- Immediately before the open parenthesis that starts the argument
list of a function call::
@ -417,8 +438,8 @@ Avoid extraneous whitespace in the following situations:
- Immediately before the open parenthesis that starts an indexing or
slicing::
Yes: dict['key'] = list[index]
No: dict ['key'] = list [index]
Yes: dct['key'] = lst[index]
No: dct ['key'] = lst [index]
- More than one space around an assignment (or other) operator to
align it with another.