[Python-Dev] ',' precedence in documentation]

Guido van Rossum guido at python.org
Mon Sep 15 06:18:56 CEST 2008


On Sun, Sep 14, 2008 at 2:01 PM, Christopher Lee <leec at chem.ucla.edu> wrote:
>
>> ----- Forwarded message from Guido van Rossum <guido at python.org> -----
>>
>> Note that in any case, the 'in' operator binds more tightly than the
>> comma: e.g. f(x in y, z) means f((x in y), z).
>
> Exactly the point I was trying to make.  As far as the user's concerned, an
> expression list
> x,y
> can itself be part of an expression;
> x in y
> is also an expression.  Such expressions can be combined to form larger
> expressions, so it follows logically that you need to know which has
> precedence when *both* occur in an expression, e.g. whether
> x in y,z
> evaluates as
> (x in y),z
> or
> x in (y,z)
>
> The page that Fredrik sent you to
> (http://docs.python.org/ref/exprlists.html) doesn't address that question.
>  I still think the precedence table
> (http://docs.python.org/ref/summary.html) should show that "in" has higher
> precedence than comma in an expression.
>
> Can anyone show us "where it is written" in the Python docs that "in" has
> higher precedence than comma, *and* why there is a good reason that this
> information should NOT be included in the precedence table?
>
> -- Chris
>
> Adding comma to the precedence table would also disambiguate expressions
> like:
> x and y,z
> x,y or z
> not x,y

You don't seem to understand how to read syntax tables. The assert
syntax is given as "assert expression , expression" and the syntax for
"expression" doesn't allow a comma unless it's inside parentheses.
That is all you need here, and that is what Fredrik pointed out. The
precedence list only applies to expressions, not to other constructs
like statements. (You might note that it also doesn't list the
precedence of 'assert'.) The place to reference is
http://docs.python.org/ref/assert.html .

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list