allow line break at operators

Steven D'Aprano steve+comp.lang.python at
Thu Aug 11 01:32:12 CEST 2011

Ian Kelly wrote:

> On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano
> <steve+comp.lang.python at> wrote:
>>> Without the parentheses, this is legal but (probably) useless; it
>>> applies the unary + operator to the return value of those functions.
>>> Putting the + at the end of the previous line at least prevents that,
>>> since most unary operators bind to the operand on the right;
>> Not so:
>>>>> x = (42 + -
>> ...     100)
>>>>> x
>> -58
> That is still binding to the operand on the "right" (i.e., the
> sequentially later).  And it still does not cause the problem that
> Chris was talking about, since without the parentheses that would be a
> syntax error.  So I guess I'm not certain what exactly it is that
> you're trying to demonstrate here.

Chris stated that putting the unary + at the end of the line
prevents "that", that being applying the unary + operator to the value on
the right. But that is not the case -- unary prefix operators in Python can
be separated from their operands by whitespace, including newlines.

(Python doesn't have any unary postfix operators.)



More information about the Python-list mailing list