Do you know of a Python library which provides mutable strings? Google returned surprisingly few results. The only usable library I found is http://code.google.com/p/gapbuffer/ which is in C but I would prefer it to be written in pure Python.
Edit: Thanks for the responses but I'm after an efficient library. That is, ''.join(list)
might work but I was hoping for something more optimized. Also, it has to support the usual stuff regular strings do, like regex and unicode.
In python, the string data types are immutable. Which means a string value cannot be updated. We can verify this by trying to update a part of the string which will led us to an error. # Can not reassign t= "Tutorialspoint" print type(t) t[0] = "M"
In Python, strings are made immutable so that programmers cannot alter the contents of the object (even by mistake).
Therefore mutable strings are those strings whose content can be changed without creating a new object. StringBuffer and StringBuilder are mutable versions of String in java, whereas the java String class is immutable. Immutable objects are those objects whose contents cannot be modified once created.
Answer 1: List mutability in Python means that one can change an item present in a list by accessing it directly as part of the assignment statement. Furthermore, one can update one of the list items by using the indexing operator on the left side of an assignment.
In Python mutable sequence type is bytearray see this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With