Python list() Function: Use, Syntax, and Examples

Python list() function: In this tutorial, we will learn about the list() function in Python with its use, syntax, parameters, returns type, and examples. By IncludeHelp Last updated : June 23, 2023

Python list() function

The list() function is a library function in Python, it is used to create a list, and it accepts multiple elements enclosed within brackets (because the list() takes only one argument. Thus, the set of elements within brackets is considered as a single argument).

Consider the below example with sample input/output values:

students = list(("Amit shukla", "prem", "Radib", "Abhi"))

students:  ['Amit shukla', 'prem', 'Radib', 'Abhi']


The following is the syntax of list() function:



The following are the parameter(s):

  • elements – list of the elements.

Return Value

The return type of list() function is <class 'list'>, it returns a list of given elements.

Python list() Example 1: Create a list with given set of elements

# 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() Example 2: Convert string to a list

# Example to convert string to a list
# using list() method

# string
vowels = "AEIOU"

# convert string to list
vowels_list = list(vowels)

# print
print("vowels_list:", vowels_list)


vowels_list: ['A', 'E', 'I', 'O', 'U']

Python list() Example 3: Create lists from set and dictionary

# set
x = {10, 20, 30, 40}

# dictionary
y = {"a": "Apple", "b": "Banana", "c": "Cat"}


[40, 10, 20, 30]
['a', 'b', 'c']

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.