A small inconsistency in syntax?
Chris Liechti
cliechti at gmx.net
Fri Oct 26 17:05:23 EDT 2001
"Steve Holden" <sholden at holdenweb.com> wrote in
news:_ohC7.38719$Nx2.821986 at atlpnn01.usenetserver.com:
> 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?
if the variables are not yet defined it raises an exception:
>>> [c,d][1] = 23
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'c' is not defined
>>> c = [a,b][1] = 23
-> c = 23 but a and b are not modified
this; [1,2][1]=23
should raise an "SyntaxError: can't assign to literal", but does not.
so there seems to be a bug in Python. but so what... its not that
important, otherwise somebody would have cought on that during the last ten
years.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list