# Python 串列(List)使用 list() 函數將其他類型的資料結構轉換為串列

Python 串列(List)是一種常用的資料結構，它可以儲存多個元素，並且可以使用 list() 函數將其他類型的資料結構轉換為串列。

list() 函數可以將元組、字典、字串等資料結構轉換為串列，並且可以指定轉換的元素數量。

## 範例一：將元組轉換為串列

```# 定義元組
tuple = (1, 2, 3, 4, 5)

# 將元組轉換為串列
list_tuple = list(tuple)

# 印出串列
print(list_tuple)
```

```[1, 2, 3, 4, 5]
```

## 範例二：將字典轉換為串列

```# 定義字典
dict = {'name': 'John', 'age': 20}

# 將字典轉換為串列
list_dict = list(dict)

# 印出串列
print(list_dict)
```

```['name', 'age']
```

## 範例三：將字串轉換為串列

```# 定義字串
string = "Hello World"

# 將字串轉換為串列
list_string = list(string)

# 印出串列
print(list_string)
```

```['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
```

Categorized in:

Tagged in:
{"ft_lang_label":"__label__zh","ft_lang_prob":0.78399855,"math_prob":0.6936515,"size":758,"snap":"2023-40-2023-50","text_gpt3_token_len":611,"char_repetition_ratio":0.12997347,"word_repetition_ratio":0.02020202,"special_character_ratio":0.3641161,"punctuation_ratio":0.20567375,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9591726,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-03T20:10:00Z\",\"WARC-Record-ID\":\"<urn:uuid:a1331ac4-e3ca-4b42-8c65-f97ede5bd937>\",\"Content-Length\":\"63825\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4993ab1b-f207-4ca0-b9af-ebfb7d511674>\",\"WARC-Concurrent-To\":\"<urn:uuid:5d4f04df-03f6-4215-ace9-6ac1e2cbbc99>\",\"WARC-IP-Address\":\"203.222.0.229\",\"WARC-Target-URI\":\"https://badgameshow.com/steven/python/%E4%BD%BF%E7%94%A8list%E5%87%BD%E6%95%B8%E5%B0%87%E5%85%B6%E4%BB%96%E8%B3%87%E6%96%99%E7%B5%90%E6%A7%8B%E8%BD%89%E6%8F%9B%E7%82%BApython%E4%B8%B2%E5%88%97/\",\"WARC-Payload-Digest\":\"sha1:CHLIBZMFMHDZ4GQVQSBOSBUXXWMSCU4Y\",\"WARC-Block-Digest\":\"sha1:EPVQQNGX3PSMTTLUVGFGYYMK3NOOOOLO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100508.53_warc_CC-MAIN-20231203193127-20231203223127-00323.warc.gz\"}"}