Pythonがstrタイプ修正を実現する方法


Pythonのstrは修正できないが,スライス操作により位相を変える挿入削除や修正などの操作が可能である.
lonfee@ubuntu:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a='0034'
>>> a[1]='1'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> a=a[:1]+'1'+a[2:]
>>> print a
0134
>>> a=a[:2]+'2'+a[2:]
>>> print a
01234
>>>