precedence of [] vs .

Fredrik Lundh fredrik at
Fri Aug 15 09:33:38 CEST 2008

Calvin Spealman wrote:e

> attribute access ( binds more tightly than subscripting (foo[bar]).

no, they have the same binding power; here's the relevant part of the 

     trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME

note however that "." only binds to a name, not a full expression (as 
Carl noted).

the summary at is broken; the 
source code for that page looks like this:

     \lineii{\code{+}, \code{-}}{Addition and subtraction}
     \lineii{\code{*}, \code{/}, \code{\%}}
            {Multiplication, division, remainder}
     \lineii{\code{+\var{x}}, \code{-\var{x}}}	{Positive, negative}
     \lineii{\code{\~\var{x}}}			{Bitwise not}
     \lineii{\code{**}}				{Exponentiation}
     \lineii{\code{\var{x}.\var{attribute}}}	{Attribute reference}
     \lineii{\code{\var{x}[\var{index}]}}	{Subscription}
     \lineii{\code{\var{x}[\var{index}:\var{index}]}}	{Slicing}
     \lineii{\code{\var{f}(\var{arguments}...)}}	{Function call}

which indicates that the author intended "." and "[" to appear in the 
same box, but got overruled by the Tex->HTML conversion tool.

(if someone has the bandwidth, please submit a documentation bug).


More information about the Python-list mailing list