a question about list as an element in a tuple

L

liuerfire Wang

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>
***********************************/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top