Interpreting Left to right?

Ben Finney ben+python at benfinney.id.au
Fri Jun 24 20:32:46 EDT 2011


Tycho Andersen <tycho at tycho.ws> writes:

> On Fri, Jun 24, 2011 at 01:24:24PM -0700, Ned Deily wrote:
> > http://docs.python.org/py3k/reference/simple_stmts.html#assignment-statements
>
> Perhaps I'm thick, but (the first thing I did was read the docs and) I
> still don't get it. From the docs:
>
> "An assignment statement evaluates the expression list (remember that
> this can be a single expression or a comma-separated list, the latter
> yielding a tuple) and assigns the single resulting object to each of
> the target lists, from left to right."

Notice that, in the grammar given there, there is exactly one
“expression list”, following *all* of the ‘=’s. The “target lists” are
each to the left of an ‘=’.

> For a single target, it evaluates the RHS and assigns the result to
> the LHS. Thus
>
> x = x['foo'] = {}
>
> first evaluates
>
> x['foo'] = {}

No, that's not an “expression list” by the grammar given in the docs.

The expression list consists, in your example, of “{}” only. The target
lists are “x”, then “x['foo']”, in that order.

-- 
 \       “If consumers even know there's a DRM, what it is, and how it |
  `\     works, we've already failed.” —Peter Lee, Disney corporation, |
_o__)                                                             2005 |
Ben Finney



More information about the Python-list mailing list