Python list() Function

The python list() creates a list in python.

Signature

Parameters

iterable (optional) - An object that can be a sequence( string, tuple etc.) or collection( set, dictionary etc.) or iterator object.

Return

It returns a list.

Python list() Function Example 1

The below example create a list from sequence: string, tuple and list.

Output:

[]
['a', 'b', 'c', 'd', 'e']
[1,2,3,4,5]
[1,2,3,4,5]

Explanation: The above example creates a list from sequence: string, tuple and list.

Python list() Function Example 2

The below example create list from collection: set and dictionary.

Output:

['e', 'c', 'd', 'b', 'a']
['c', 'e', 'd', 'b', 'a']





Latest Courses