Structure
The list is perhaps the most commonly used data structure in Python. It allows us to store elements of different data types in one container.
The contents of a list are enclosed by square brackets, [].
Lists are ordered, like strings. Elements are stored linearly at a specific index.
svg viewer
We can see from the illustration above that a list bears resemblance to a string.
A string is a collection of characters indexed in a linear fashion. A list is the same except that it can contain any type of data, even another list!
Creating a List
Let’s see how to create a list using square brackets.
Structure
Creating a List
Using range()
List-Ception!
Sequential Indexing
Merging Lists
Structure
The list is perhaps the most commonly used data structure in Python. It allows us to store elements of different data types in one container.
The contents of a list are enclosed by square brackets, [].
Lists are ordered, like strings. Elements are stored linearly at a specific index.
svg viewer
We can see from the illustration above that a list bears resemblance to a string.
A string is a collection of characters indexed in a linear fashion. A list is the same except that it can contain any type of data, even another list!
Creating a List
Let’s see how to create a list using square brackets.