list()

renerepina's avatar
Published Nov 10, 2022Updated May 11, 2023
Contribute to Docs

The list() function returns a list from an iterable.

Syntax

list(iterable)

The iterable parameter can be one of the following:

If no iterable is passed, the list() function returns an empty list.

Example

The example below demonstrates how the list() function is used to create a list from a dictionary:

language_difficulties = list({"Python" : "Hard", "Java" : "Medium", "HTML" : "Easy"})
print(language_difficulties)
empty_list = list()
print(empty_list)

This will print the following output:

['Python', 'Java', 'HTML']
[]

Codebyte Example

The following examples shows three different cases of using the list() function:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy