list()函数是一个库函数,它用于创建列表,它接受括在方括号内的多个元素(因为list()仅接受一个论点。因此,方括号内的元素集被视为单个参数)。
语法:
list((elements))
Parameter(s): elements –元素列表。
返回值: list –返回给定元素的列表。
示例
Input: students = list(("Amit shukla", "prem", "Radib", "Abhi")) Output: students: ['Amit shukla', 'prem', 'Radib', 'Abhi']
使用以下代码创建列表的Python代码 list() 功能
# python代码演示示例 # list() method # 创建列表 students = list(("Amit shukla", "prem", "Radib", "Abhi")) # printing type of list() function print("type of list() function: ", type(students)) # 打印列表... print("students: ", students)
输出结果
type of list() function: <class 'list'> students: ['Amit shukla', 'prem', 'Radib', 'Abhi']