In python, are strings mutable? The line someString[3] = "a" throws the error
TypeError: ‘str’ object does not
support item assignment
I can see why (as I could have written someString[3] = “test” and that would obviously be illegal) but is there a method to do this in python?
Python strings are immutable, which means that they do not support item or slice assignment. You’ll have to build a new string using i.e.
someString[:3] + 'a' + someString[4:]or some other suitable approach.