code review

Steven D'Aprano steve+usenet at
Sun Jul 1 08:27:37 CEST 2012

On Sun, 01 Jul 2012 14:23:36 +1000, Chris Angelico wrote:

> On Sun, Jul 1, 2012 at 2:17 PM, Steven D'Aprano
> <steve+comp.lang.python at> wrote:
>> Nonsense. Of course parens change the evaluation of the expression.
>> That's what parens are for!
> The whole point of my example was that it wouldn't.

Yes, you can find specially crafted examples where adding parentheses in 
certain places, but not others, doesn't change the overall evaluation of 
the expression. So what? IN GENERAL, adding parentheses changes the 
evaluation of the expression -- that is what they are for.

Therefore, IN GENERAL you should expect that adding parentheses will 
change the result, unless you carefully place them where you know that 
they will have no effect.

Even in C, I can't just do this:

=> (2+3)*4

with the expectation that you can stick parentheses around the left-most 
term without changing the value. The fact that you can do for some 
expressions is irrelevant.

In general, if you don't know the semantics of an expression (including 
the operator precedence), you cannot just assume that adding parens is 


More information about the Python-list mailing list