Turple
不可變串列稱為Turple
相對於可變串列只能執行Query類操作
Turple字面值
1. () # 空串列
2. (1,2,3) # 三個項目
3. (1, (4,5,6)) # 巢狀串列
4. (1, "abc", 3) # 異質串列
內建運算
arr = (1,2,3)
Query:
1. arr[0] == 1 # 索引運算
2. arr[-1] == 3 # 負索引
3. arr[1:3] == (2,3) # 切片
4. arr[0:3] == (1,2,3) # 切片
5. arr[:3] == arr[0:3] # True
6. arr[:-1] == arr[0:2] # True
7. arr[:] == (1,2,3) # 拷貝
8. arr + (4,5,6) == (1,2,3,4,5,6) # 串接
9. arr * 2 == (1,2,3,1,2,3) # 重複