There are lots of article to say that tuple in pyton in immutable, but after
my test, this is not true.
Please see the example:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on
win32
L = [1,2,3]
define a typle
dd = tuple(L)
print all methods of tuple
print dir(dd)
[‘add‘, ‘class‘, ‘contains‘, ‘delattr‘, ‘doc‘, ‘eq‘,
‘
format‘, ‘ge‘, ‘getattribute‘, ‘getitem‘, ‘getnewargs‘,
‘get
slice‘, ‘gt‘, ‘hash‘, ‘init‘, ‘iter‘, ‘le‘, ‘len‘,
‘
lt‘, ‘mul‘, ‘ne‘, ‘new‘, ‘reduce‘, ‘reduce_ex‘,
‘repr‘
, ‘rmul‘, ‘setattr‘, ‘sizeof‘, ‘str‘, ‘subclasshook‘,
‘count
‘, ‘index’]
print dd
(1, 2, 3)
dd.add(“a”)
Traceback (most recent call last):
File ““, line 1, in
TypeError: can only concatenate tuple (not “str”) to tuple
# Note, tuple is changed.
dd.add(dd)
(1, 2, 3, 1, 2, 3)
refs: http://www.diveintopython.net/native_data_types/tuples.html