assignment to reference

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Thu Oct 27 02:50:10 EDT 2005


Bruno Desthuilliers enlightened us with:
> for obj in (a, b, c):
>    if obj == 'cabbage':
>      obj = 'coconut'

Doesn't work on my Python:

Python 2.4.2 (#2, Sep 30 2005, 21:19:01) 
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 'apple'
>>> b = 'banana'
>>> c = 'cabbage'
>>> for obj in (a, b, c):
...    if obj == 'cabbage':
...      obj = 'coconut'
... 
>>> c
'cabbage'
>>>

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list