1. 程式人生 > >集合裏面嵌套列表,會報錯卻是可變的

集合裏面嵌套列表,會報錯卻是可變的

mod ack err typeerror port mos ace sign stdin

>>> s = (1,2,3,[2,3])
>>> s
(1, 2, 3, [2, 3])
>>> s[3] + [5,6]
[2, 3, 5, 6]
>>> s[3] += [5,6]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ‘tuple‘ object does not support item assignment
>>> s
(1, 2, 3, [2, 3, 5, 6])

集合裏面嵌套列表,會報錯卻是可變的