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

Christopher Lee leec at chem.ucla.edu
Mon Sep 15 20:50:21 CEST 2008

On Sep 14, 2008, at 9:18 PM, Guido van Rossum wrote:

> 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 .

Thanks.  This is such a striking difference from C, where many of us  
draw our default language assumptions, that it might be worth  
highlighting in the Python docs, e.g. on the expression list page.   
Maybe something like <<Note: Python does not define comma as an  
operator, but instead just uses it as a separator in expression lists,  
function argument lists, and many other contexts.  Note also that this  
disambiguates precedence: expression operators have higher precedence  
than the commas of an expression list.  Thus the expression list "x  
and y, z" evaluates as "(x and y), z", not "x and (y, z)".>>   
Highlighting this would stop people with C backgrounds from assuming  
that comma is an operator, like I did.  Analyzing the full syntax  
table would obviously sort this out, but a lot of people just read the  
docs (like I did :-)...

More information about the Python-Dev mailing list