A small inconsistency in syntax?

Steve Holden sholden at holdenweb.com
Fri Oct 26 13:55:26 EDT 2001


"Rainer Deyke" <root at rainerdeyke.com> wrote in ...
> "Chris Barker" <chrishbarker at home.net> wrote in ...
> > Terry Reedy wrote:
> >
> > > As I understand it, the rule is this:  if item on LHS is tuple rather
> > > than name, then corresponding object on RHS must be a tuple, which
> > > will then be seen as collection rather than object in itself and
> > > consequently unpacked for matching to items within LHS tuple.
> > > Allowing for null matches and applying the rule recursively,
> >
> > Actually either side can be a sequence, not just a tuple:
>
> Nitpick: Although the LHS can be written as either a tuple literal or a
list
> literal, it is in fact not an object at all, and hence not a tuple, list,
or
> any other kind of sequence:
>
> a, b = 3, 4  # a <- 3; b <- 4
> a_b = a, b
> a_b = 3, 4 # Does not affect the value of 'a' or 'b'.
> tuple((a, b)) = 3, 4 # Syntax error.
>

This is getting TOO weird. Should this really be allowed? Does it make any
kind of sense? The attached comes from 2.0, but 2.1.1 and 2.2b1 give the
same result.

>>> [a,b] = (1,2) # no surprises here
>>> a
1
>>> b
2
>>> [a,b][1] = 23 # WHAT!?!?!?!?!?!?
>>> b
2

What does the interpreter actually DO with this statement, and why is it
allowed? To what is the value 23 actually bound here?

regards
 Steve
--
http://www.holdenweb.com/







More information about the Python-list mailing list