Lists

Now that we have finished working on numbers and strings, let's work with the lists and sublists.

Lists

Python lists are data structures that group sequences of elements. Lists can have elements of several types, and you can also mix different types within the same list (although all elements are usually of the same datatype).

Lists are created using square brackets [], and the elements are separated by commas (,). The elements in a list can be accessed by their positions, starting with 0 as the index of the first element.

list=[element1,element2,...]

For example, to create list l with five elements, write

l=[1,2,3,4,5]

Get hands-on with 1000+ tech skills courses.