Instructor: Welcome back.
Let's talk about our next data type,
and it's a big one, a very, very useful one.
It's called list.
And list is an ordered sequence of objects
that can be of any type.
So you can think of them as strings, right?
We had strings previously that we learned about,
except that each sequence of this string,
well, was a string, was a letter
or a number wrapped in quotation marks.
Lists, on the other hand, looks something like this.
Let's say we create a variable, li,
and lists we denote with square brackets,
and inside of these square brackets,
we can have different objects.
So for example, we can have 1, 2, 3, 4, 5.
We can also have, let's say li2,
and this is going to have a, b, c,
and it can have any collection of items that we want.
We can even mix and match,
and say that we have one, two, then a,
then maybe even the Boolean value true.
So all of these are lists.
Now, lists are extremely important,
and in other programming languages
you might have heard the word arrays.
So in Python, lists are a form of array,
and later on when we get into the modules section
of the course, we will talk about the difference
between lists and arrays.
But if you are coming
from a different programming background,
then lists are like arrays in your language,
a collection of items.
Now, the neat thing about lists is
that it's the first data structure that we're learning.
Now, what is a data structure?
Data structure is a very important concept
in programming languages.
It's a way for us to organize information and data
into, let's say, a folder or a cupboard or a box,
so that these data structures can be used
with different pros and cons.
For example, you have a fridge where you store your food,
and fridges are really, really good
at putting your food inside, keeping it cold,
and then taking it out.
Or you might have a backpack.
A backpack is really really good
to stuff everything in there.
But when you're looking for things in a backpack,
it's really, really hard.
So you can think of data structures as similar to that,
a container around your data
that has different pros and cons
of accessing that data, removing that data, writing data.
But that's something we'll get into a little bit later.
The key here is that these square brackets
allow us to contain information and data,
like strings, integers, floats, if we want to
Booleans, into a contained fashion.
So let's think of a good example here.
What if we had a shopping cart?
Let's say we're Amazon here,
and then Amazon has the Amazon shopping cart,
and in here we can collect different things that we want.
Maybe we collect some, I don't know, notebooks
And you know what?
Let's get some gadgets.
Let's get some, maybe some sunglasses.
We can add different items here, different strings,
different data into this cart.
And now, just like we saw in strings,
we can access the Amazon cart in different ways.
For example, I can access it, again,
with square brackets and simply say, I want item zero.
So if I print here,
and do amazon_cart,
look at that, I get notebooks.
The second item,
I get sunglasses.
What about the third item?
Nope, list index out of range.
But this should make sense now.
This is a list where we're accessing the index of,
but it only contains two items.
So if we're going zero, 1, 2,
the third item, nothing exists.
So our program says that doesn't work.
You're doing something wrong.
And just like strings, these list items are in memory
in their separate bookshelf, right?
But one right next to each other.
So we can go 0, 1, 2, 3, 4, 5,
so on and so forth until the list ends.
All right, let's learn about lists a lot more
in the next video, bye-bye.