Refeing to substring in list of strings

Andrew Dalke dalke at acm.org
Sat Apr 8 14:31:31 EDT 2000


David Fisher
> If you're trying to assign to the substring, like s[1:2] = 'e',
> you can't, strings are immutable.


So the usual solution is to do things like:

  s = s[:lborder] + new_substr + s[:rborder]

You might also want to play around with array.array

s = "This is a string"
import array
a = array.array("c", s)
a[5:7] = array.array("c", "was")
print a.tostring()

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list