研究了一下,tuple 的元素不能被修改,而 list 则可以:
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(tmp)-
[21827 0] %[/color] python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 1, 2, 3, 4
>>> a
(1, 2, 3, 4)
>>> a = (1, 2, 3, 4)
>>> a
(1, 2, 3, 4)
>>> a[0] = 11
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
>>> a = [1, 2, 3, 4]
>>> a
[1, 2, 3, 4]
>>> a[0] = 11
>>> a
[11, 2, 3, 4]
>>> ^D
[color=blue]-(guest@mac:tty1)-(tmp)-
[21827 0] %[/color]