Home / Python / Reference / Built-in functions

Python list() function

Make a new list, empty or from any iterable.

Syntax

list(iterable=())

Turns strings, tuples, sets, ranges, dictionary views and generators into a list. Also a quick way to copy a list.

Parameters

iterableanything you can loop over

Return value

list

Example

Code

print(list("abc"))
print(list(range(5)))
print(list((1, 2, 3)))
print(list({"a": 1, "b": 2}))        # the keys
a = [1, 2]
b = list(a)                          # a copy
b.append(3)
print(a, b)

Output

['a', 'b', 'c']
[0, 1, 2, 3, 4]
[1, 2, 3]
['a', 'b']
[1, 2] [1, 2, 3]

Related

Learn it step by step in the free lesson Lists & Tuples, with exercises that check your answers.