xxxxxxxxxx
<ul>
<li>Lorem ipsum dolor sit.</li>
<li>Expedita perferendis saepe quas.</li>
<li>Dolorem at fugit quam.</li>
</ul>
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.
xxxxxxxxxx
jon_snow = ["Jon Snow", "Winterfell", 30]
print(jon_snow)
# Indexing
print(jon_snow[0])
# Length
print(len(jon_snow))
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.
xxxxxxxxxx
jon_snow = ["Jon Snow", "Winterfell", 30]
print(jon_snow)
# Indexing
print(jon_snow[0])
# Length
print(len(jon_snow))