My first Python program

Ian Kelly ian.g.kelly at gmail.com
Wed Oct 13 14:07:56 EDT 2010


On Wed, Oct 13, 2010 at 11:28 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

> Seebs wrote:
>
>> On 2010-10-12, Hallvard B Furuseth <h.b.furuseth at usit.uio.no> wrote:
>>
> >
>
>>  self.type, self.name = None, None
>>>>
>>>
>>  Actually you can write self.type = self.name = None,
>>> though assignment statements are more limited than in C.
>>> (And I think they're assigned left-to-right.)
>>>
>>
> Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> --> a = 2
> --> b = 7
> --> c = 13
> --> a = b = c = 'right to left'
> --> a, b, c
> ('right to left', 'right to left', 'right to left')
>

I'm not sure how that demonstrates anything, but 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.

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


More information about the Python-list mailing list