list とよく似ているが、immutable である。
>>> x=() >>> x () >>> x=(1) >>> x 1 >>> x=(1,) >>> x (1,) >>> x=(1,'two') >>> x (1, 'two') >>> x[0] 1 >>> x(1) 'two' >>> x[1]=2 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment >>> x=(1,2) >>> x (1, 2) >>> x.append(3) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'tuple' object has no attribute 'append' |