Python list() 函數
list() 函數是一個庫函數,用於創建一個列表,它接受括號內的多個元素(因為 list() 隻接受一個參數。因此,括號內的元素集合被視為單個參數)。
用法:
list((elements))
參數: elements
– 元素列表。
返回值: list
– 它返回給定元素的列表。
例:
Input: students = list(("Amit shukla", "prem", "Radib", "Abhi")) Output: students: ['Amit shukla', 'prem', 'Radib', 'Abhi']
使用 list() 函數創建列表的 Python 代碼
# python code to demonstrate example of
# list() method
# creating list
students = list(("Amit shukla", "prem", "Radib", "Abhi"))
# printing type of list() function
print("type of list() function:", type(students))
# printing list...
print("students:", students)
輸出
type of list() function: <class 'list'> students: ['Amit shukla', 'prem', 'Radib', 'Abhi']
相關用法
- Python list remove()用法及代碼示例
- Python list index()用法及代碼示例
- Python list copy()用法及代碼示例
- Python list insert()用法及代碼示例
- Python list pop()用法及代碼示例
- Python list sort()用法及代碼示例
- Python list reverse()用法及代碼示例
- Python linecache.getline()用法及代碼示例
- Python locals()用法及代碼示例
- Python PIL logical_and() and logical_or()用法及代碼示例
- Python len()用法及代碼示例
- Python numpy string less_equal()用法及代碼示例
- Python calendar leapdays()用法及代碼示例
- Python ldexp()用法及代碼示例
- Python PIL logical_xor() and invert()用法及代碼示例
- Python log10()用法及代碼示例
- Python Functools lru_cache()用法及代碼示例
- Python lzma.LZMACompressor()用法及代碼示例
- Python string lstrip()用法及代碼示例
- Python numpy.less()用法及代碼示例
注:本文由純淨天空篩選整理自 list() function with example in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。