1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| >>> a = (1,2)
>>> a+1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate tuple (not "int") to tuple
>>> a+(1,)
(1, 2, 1)
>>> a = (1,2,3)
>>> b = (2,3,4)
>>> a+b
(1, 2, 3, 2, 3, 4)
|
Tuple最特别在于
tuple元素不允许删除或修改,但是可以通过连接tuple来实现简介修改/或转置为list