VOOZH about

URL: https://www.codecademy.com/resources/docs/python/built-in-functions/list

⇱ Python | Built-in Functions | list() | Codecademy


Skip to Content

Python list()

Preview: @renerepina 4 total contributions
@renerepina

4 total contributions

Published Nov 10, 2022Updated May 11, 2023

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

  • Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
    • Includes 27 CoursesIncludes 27 Courses
    • With Professional CertificationWith Professional Certification
    • Beginner Friendly.
      95 hours95 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With CertificateWith Certificate
    • Beginner Friendly.
      24 hours24 hours

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)
Copy to clipboard
Copy to clipboard

This will print the following output:

['Python', 'Java', 'HTML']
[]
Copy to clipboard
Copy to clipboard

Codebyte Example

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

Visit us
Visit us
Hide code
Code
Output
Hide output
Copy to your clipboard

All contributors

Learn Python on Codecademy

  • Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
    • Includes 27 CoursesIncludes 27 Courses
    • With Professional CertificationWith Professional Certification
    • Beginner Friendly.
      95 hours95 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With CertificateWith Certificate
    • Beginner Friendly.
      24 hours24 hours