我刚看到一些非常奇怪的东西.
>>> t = ([],)
>>> t[0].append('hello')
>>> t
(['hello'],)
>>> t[0] += ['world']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> t
(['hello', 'world'],)
Run Code Online (Sandbox Code Playgroud)
为什么它会提升TypeError并改变list内部tuple?
python ×1