Pythonian string manipulation.

johnvert at my-deja.com johnvert at my-deja.com
Sat Jan 6 11:51:50 EST 2001


Hi,

I was playing around with slices in Python (is that the correct term?)
and I tried, in order to switch the words `hello,' and `world', to do:

s = 'hello, world'
l = s.find(',')
s[0:l] = s[l + 1:]

which in theory would seem to work, but I get the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support slice assignment

my two questions are: why isn't this allowed, and what is the Pythonian
way of doing this?

Thanks,
 -- John


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list