3 ms·
>>> a = "string" >>> a[1] = 'g' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item a
by pyre 14y ago
>>> a = "string"
>>> a[1] = 'g'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> b = a.replace('t', 'g')
>>> b
'sgring'
>>> a
'string'
>>> id(b)
3065252256L
>>> id(a)
3075481632L
Also from here[1]:
Strings and tuples are immutable sequence types: such
objects cannot be modified once created.
[1] http://docs.python.org/2/library/stdtypes.html#mutable-sequence-types http://docs.python.org/2/library/stdtypes.html#mutable-seque...