Slice assignment for strings?

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Tue May 25 12:30:11 EDT 2004


Jens Lippmann wrote:
> So, my questions are:
> - How do I get it right?
> - If slicing seems to be the favorite way to address substrings, why
>   is it impossible to use it on a left side of an assignment?
> 

Strings are immutable in python; it means you cannot change them
in-place.  You can still change the value of variables and do things like:
a = "hello"
a = "a" + a[2:]  # producing allo

Strings are immutable, but there's (mutable) containers that might do a 
better job for what you want to do.  Module array could be a possible 
solution (and I'm sure there's others).

Regards,
Nicolas



More information about the Python-list mailing list