Python list() Function


Python list() is a built-in function that takes an iterable as a function parameter and returns a list constructed from that iterable.

python list() function

Python list() Syntax

list([iterable])

list() takes one argument.

When no argument is supplied, list() method creates an empty list.

Python list() Example

>>> #creating an empty list
>>> list()
[]

>>> #creating list from a tuple
>>> py_tuple = ('x','y','z')
>>> list(py_tuple)
['x','y','z']

>>> #creating a list from a string
>>> py_string = 'python'
>>> list(py_string)
['p','y','t','h','o','n']

>>> #creating a list from a dictionary
>>> py_dict = {'1':'a','2':'b','3':'c'}
>>> list(py_dict)
['1', '2', '3']

Note: When a dictionary is supplied as the argument, list() returns a list constructed from only keys of the dictionary.