[Chicago] I don't get why this works
Martin Maney
maney at two14.net
Wed Apr 3 03:55:47 CEST 2013
On Mon, Apr 01, 2013 at 10:24:46PM -0500, Brantley Harris wrote:
> > a = {}
> > a['a'] = a[a['a']] = 'b'
> {'a': 'b', 'b': 'b'}
>
> What the what? I would think that should KeyError, but it runs fine.
> Someone splain.
Because assignment is... well, first, it's not value assignment, it's
binding, which is I guess why in Python assignment is defined only as
its own special type of statement (language reference, 6.2) rather than
as an operator (part of expression syntax). As for why it works left
to right, that's just because.
/me wonders what pylint has to say about multi-target assignment...
--
The theory of multiple intelligences fundamentally conflates
intelligence and motivation. -- Christopher J. Ferguson
More information about the Chicago
mailing list