Latest web development tutorials

Python3 List list()方法

Python3 列表 Python3列表


描述

list() 方法用於將元組轉換為列表。

注:元組與列表是非常類似的,區別在於元組的元素值不能修改,元組是放在括號中,列表是放於方括號中。

語法

list()方法語法:

list( seq )

參數

  • list -- 要轉換為列表的元組。

返回值

返回列表。

實例

以下實例展示了list()函數的使用方法:

#!/usr/bin/python3

aTuple = (123, 'Google', 'w3big', 'Taobao')
list1 = list(aTuple)
print ("列表元素 : ", list1)

str="Hello World"
list2=list(str)
print ("列表元素 : ", list2)

以上實例輸出結果如下:

列表元素 :  [123, 'Google', 'w3big', 'Taobao']
列表元素 :  ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

Python3 列表 Python3列表