September 2026
1051 pages
35h 4m
English
In this section, you’ll learn about the first mutable data type, list, in detail. Unlike the str, bytes, and bytearray sequential data types, which can only store elements (characters) of the same type, lists are suitable for managing any kind of instances, even of different data types. A list can therefore contain numbers, strings, or even other lists as elements.
You can create a new list by writing an enumeration of its elements in square brackets []:
>>> l = [1, 0.5, "String", 2]
The list l now contains two integers—a float and a string.
A list can also be generated via list comprehension. In that case, not all elements of the list are explicitly listed but are generated via a formation rule similar to a ...
Read now
Unlock full access