> For the complete documentation index, see [llms.txt](https://dinoin.gitbook.io/shi-py-bu-shi-pi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dinoin.gitbook.io/shi-py-bu-shi-pi/tuple-yuan-zu.md).

# Tuple(元組)

很類似list的東西

可以想成是「不能修改的List」，儲存資料比較安全，執行速度比list快。

使用「()」(list用「\[]」)。

```python
tp = ('a', 'b') # 新建立
print(tp[1]) # 取值
> b
```

{% code title="可以與list互相轉換" %}

```python
ironman_tuple = ("中信兄弟", "統一獅", "lamigo", "富邦悍將")
ironman_list = ["brother","lion","monkey","Guardians"]
tuple_to_list = list(ironman_tuple)
list_to_tuple = tuple(ironman_list)
```

{% endcode %}

> 參考：<https://ithelp.ithome.com.tw/articles/10200547>

## tuple to string

[在這](/shi-py-bu-shi-pi/string.md#tuple-to-string)
