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
Thank you all for your replies. They have helped me understand
that immutable means just that! Blame my c heritage where a
pointer allows you to scribble over anything.
--
http://mail.python.org/mailman/listinfo/python-list
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
Loris Caren enlightened us with:
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
Loris Caren wrote:
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?
if you need a
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 apparently don't understand this question in the same way the way
others do. I think the question is about the mutability of strings.
To my understanding of your question, it is impossible, at least if the
referenced objects are strings or other objects of immutable type.
'cabbage' cannot be