python中修改元组元素的值
1、
>>> a = ("aaa","bbb","ccc","ddd","eee","fff")
>>> type(a)
<class 'tuple'>
>>> id(a)
1360669254176
>>> a[2] = "xxx"
Traceback (most recent call last):
File "<pyshell#372>", line 1, in <module>
a[2] = "xxx"
TypeError: 'tuple' object does not support item assignment
>>> a[:1] + (a[1],"xxx") + a[3:]
('aaa', 'bbb', 'xxx', 'ddd', 'eee', 'fff')
>>> a = a[:1] + (a[1],"xxx") + a[3:]
>>> a
('aaa', 'bbb', 'xxx', 'ddd', 'eee', 'fff')
>>> id(a)
1360669566816