a question about list as an element in a tuple

liuerfire Wang liuerfire at gmail.com
Sun Dec 15 22:30:13 EST 2013


Just like below:

In [1]: a = ([], [])

In [2]: a[0].append(1)

In [3]: a
Out[3]: ([1], [])

In [4]: a[0] += [1]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-ea29ca190a4d> in <module>()
----> 1 a[0] += [1]

TypeError: 'tuple' object does not support item assignment

In [5]: a
Out[5]: ([1, 1], [])

no problem, there is an exception. But a is still changed.

is this a bug, or could anyone explain it?

thanks.


-- 
Best regards.
/**********************************
google+: +liuerfire <http://gplus.to/onepiece> twitter:
@liuerfire<https://twitter.com/#!/liuerfire>
蛋疼不蛋疼的都可以试着点一下~^_^~ <http://db.tt/YGEdRM0>
***********************************/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131216/611930f7/attachment.html>


More information about the Python-list mailing list