Computer >> Computer tutorials >  >> Programming >> Python

How do we define lists in Python?


A List is a sequence data type in Python. It is a comma separated list of elements, not necessarily of same type, included in square brackets ([ ]). List is an ordered collection. Individual element in a List object can be accessed by a zero based index.

Example

list1 = ['physics', 'chemistry', 1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
list3 = ["a", "b", "c", "d"]

Output

A List object with no element between square brackets is a null list.

list1 = []