Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mutable strings in Python

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.

like image 824
Ecir Hana Avatar asked May 13 '12 14:05

Ecir Hana


People also ask

What is string mutable in Python?

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"

Does Python have mutable strings?

In Python, strings are made immutable so that programmers cannot alter the contents of the object (even by mistake).

What is a mutable string?

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.

What is mutable in Python list?

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.


1 Answers

In Python mutable sequence type is bytearray see this link

like image 77
Jason M Avatar answered Sep 21 '22 09:09

Jason M