>>> t=('a','b',"'c','d'")
>>> print t
('a', 'b', "'c','d'")
>>> print t[0]
a
>>> print t[2]
'c','d'
>>> L=t[2]
>>> L[1]
'c'
>>> L[1]='D'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment两个问题:1 为何L[1]输出的是c,不应该是d吗?2 为何教程4.9内可以给L赋值,而我这边不行?谢谢!
1 回答
昵称2_18位中英文
TA贡献1条经验 获得超2个赞
知道问题了,如下两段代码可以说明:
>>> t=('a','b','"c","d"') >>> L=t[2] >>> L '"c","d"' >>> L[0] '"' >>> L[1] 'c' >>> L[2] '"' >>> L[3] ',' >>> L[4] '"' >>> L[5] 'd' >>> t=('a','b',['A','B']) >>> L=t[2] >>> L[0] 'A' >>> L[1]='C' >>> t ('a', 'b', ['A', 'C']) >>>
添加回答
举报
0/150
提交
取消