# Tuple

>>> (1, 'Justin', 93)
(1, 'Justin', 93)
>>> 1, 'Justin', 93
(1, 'Justin', 93)
>>> data = (1, 'Justin', 93)
>>> data[0]
1
>>> data[0:2]
(1, 'Justin')
>>> data[0:]
(1, 'Justin', 93)
>>> for elem in data:
...     print(elem)
...
1
Justin
93
>>> (1, 'Justin', 93) + (2, 'momor', 99)
(1, 'Justin', 93, 2, 'momor', 99)
>>> (1, 'Justin', 93) * 2
(1, 'Justin', 93, 1, 'Justin', 93)
>>>

>>> (1)
1
>>> (1,)
(1,)
>>> tuple([1])
(1,)
>>> tuple([1, 2])
(1, 2)
>>>

>>> t1 = (3, 6, 1, 2, 7)
>>> l1 = list(t1)
>>> l1.sort()
>>> t1 = tuple(l1)
>>> t1
(1, 2, 3, 6, 7)
>>>

Tuple的內容不可變動，指的是不能變動每個索引所參考的物件，而不是指物件本身不能變動。例如：
>>> t = ([1, 2], [3, 4])
>>> t
([1, 2], [3, 4])
>>> t[0] = [10, 20]

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> t[0][0] = 10
>>> t[0][1] = 20
>>> t
([10, 20], [3, 4])
>>>

>>> t = ([1, 2], [3, 4])
>>> l = t[0]
>>> l[0] = 10
>>> l[1] = 20
>>> t
([10, 20], [3, 4])
>>>

Tuple的內容，可以同時指定給多個變數。例如：
>>> x, y = 1, 2
>>> x
1
>>> y
2
>>> t = (10, 20)
>>> x, y = t
>>> x
10
>>> y
20
>>> x, y = y, x
>>> x
20
>>> y
10
>>>

>>> [x, y] = [1, 2]
>>> x
1
>>> y
2
>>> x, y = [1, 2]
>>> x
1
>>> y
2
>>> (x, y) = [1, 2]
>>> x
1
>>> y
2
>>> x, y = {1, 2}
>>> x
1
>>> y
2
>>> x, y, z = 'Joe'
>>> x
'J'
>>> y
'o'
>>> z
'e'
>>>

>>> s = [1, 2, 3, 4, 5]
>>> a, *b = s
>>> a
1
>>> b
[2, 3, 4, 5]
>>> *a, b = s
>>> a
[1, 2, 3, 4]
>>> b
5
>>> *a, b, c = s
>>> a
[1, 2, 3]
>>> b
4
>>> c
5
>>> a, *b, c = s
>>> a
1
>>> b
[2, 3, 4]
>>> c
5
>>>