Python list() | List class in Python
The list() class in Python creates a list object where the list object is a collection which is ordered and changeable.
Syntax
class list([iterable])
Parameter
Iterable: It is a required parameter which represents a sequence, collection or an iterator object
Return
It returns a list of the specified object.
Example 1
# Python program explaining
# the list() class
week_list = list(('Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday','Sunday'))
print("Days in a week are:\n",week_list)
Output
Days in a week are: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
Example 2
# Python program explaining
# the list() class
# Multi-Dimensional List
inp_list = [['Tutorials', 'And'] , ['Examples']]
print("Multi-Dimensional List: ")
print(inp_list)
# list with duplicate values
inp_list = list((1, 2, 4, 4, 3, 3, 3, 6, 5))
print("List returns: ")
print(inp_list)
Output
Multi-Dimensional List: [['Tutorials', 'And'], ['Examples']] List with the use of Numbers: [1, 2, 4, 4, 3, 3, 3, 6, 5]
