assignment to reference

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Oct 26 17:26:17 EDT 2005


Loris Caren a écrit :
> If
> 
> a = 'apple'
> b = 'banana'
> c = 'cabbage'
> 
> How can I get something like:-
> 
> for i in 'abc':
>     r = eval(i)    
>     if r == 'cabbage': r = 'coconut'
> 
> actually change the object referenced by r rather
> than creating a new object temporarily referenced by it?
> 
> I've tried playing with eval and exec without the desired
> effect.

for obj in (a, b, c):
   if obj == 'cabbage':
     obj = 'coconut'




More information about the Python-list mailing list