September 2026
1051 pages
35h 4m
English
Let’s now turn to lists. A list is an ordered collection of elements of any data type. To create a list, the literals of the values it should contain are written in square brackets separated by commas:
>>> [1,2,3][1, 2, 3]>>> ["This", "is", "a", "list"]['This', 'is', 'a', 'list']
In addition, list elements may be defined in form of expressions:
>>> [-7 / 4, 5 * 3][-1.75, 15]
The elements of a list do not all have to be of the same type and in particular can be lists themselves, as the following example shows:
>>> ["Python", 1, 2, -7 / 4, [1,2,3]]['Python', 1, 2, -1.75, [1, 2, 3]]
Similar to strings, lists can be extended by elements with the + operator; + forms the concatenation of two lists.
>>> [1,2,3] + ["Python", "is",
Read now
Unlock full access