multiple assignments (was: My first Python program)

Ian Kelly ian.g.kelly at gmail.com
Thu Oct 14 12:38:26 EDT 2010


On Wed, Oct 13, 2010 at 3:53 PM, Ethan Furman <ethan at stoneleaf.us> wrote:

> Ian Kelly wrote:
>
>>  here is an example
>> where the order of assignment actually matters:
>>
>>  >>> d['a'] = d = {}
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> NameError: name 'd' is not defined
>>  >>> d = d['a'] = {}
>>  >>> d
>> {'a': {...}}
>>
>> As you can see, they're assigned left-to-right.
>>
>
> <Flash of inspiration>
>
> Ah!  I was thinking the assignments went in a filter fashion, but now what
> I think is happening is that the first item is bound to the last, then the
> next item is bound to the last, etc, etc.
>
> Is this correct?
>

Exactly.

Cheers,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101014/baf777c0/attachment.html>


More information about the Python-list mailing list