peps: Clarify space around colon in slice (severa cases).

http://hg.python.org/peps/rev/e98737176f1d changeset: 5538:e98737176f1d user: Guido van Rossum <guido@python.org> date: Sun Aug 31 20:18:33 2014 -0700 summary: Clarify space around colon in slice (severa cases). files: pep-0008.txt | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pep-0008.txt b/pep-0008.txt --- a/pep-0008.txt +++ b/pep-0008.txt @@ -408,6 +408,27 @@ 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 @@ - 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. -- Repository URL: http://hg.python.org/peps
participants (1)
-
guido.van.rossum