Hi, everybody, and welcome.
So we have completed successfully the valuable part of the course, and today we're going to begin a
whole new topic that will last several lectures.
We will learn about our collections and quickly comparing collections to variables.
So variables, a variable, any type of variable, it can contain only one value inside it, as we studied
in the last lectures.
And the difference between a collection and a variable is that the collection can contain several values
inside or even a lot of values inside as we wish.
So this is the difference between a variable and a collection.
So collection is like a headline inside the collections.
We have four types of collections.
But before let's just let me just say that collection is a container that store several items of values
inside and we will begin by the definition of collections and then go over to the first one, which
is a list, which is the first type of collection that we're going to study.
So using these collections, we can store any type of data that is related in some manner.
What that means basically that in our code, when we have several values that are connected in some
way, we would like to create a collection and store them all inside the collection.
Instead of having, for example, five variables, we can make one collection and put the items one
after the other in this collection.
So starting from this point, A, I will lose the term collections and I'll start using the term list
because this is the first collection type that we're going to study.
And in the following next year, of course, we will go over a dictionary set and tuple.
And each of these will contain three parts, same as the very variable part.
First part is three is what we're studying right now.
The second part will be examples in the code and the third part will be practice.
So hang on, guys, and B, be brave.
And as long as you'll listen and as long as you practice, you will be fine.
We'll be just fine.
All right.
So let's begin, for example, let's just give a quick example of a list.
For example, I can prepare a list of ages that inside I can put ages which are divided with a comma.
I can make a collection of fruits and put names of fruits inside the collection, a banana, an apple
and a watermelon and so on.
So these collections has have something in comment regarding their values.
All right.
So let's begin by starting with the first collection type, which is a list.
So let's go over the characteristics of a list.
All right.
So in Python, Aliased is created by placing all the values or in other words, elements inside square
brackets as so.
All right, so these square brackets mean that this is a list.
All right, so the values inside should be separated by commas between each value.
And the second thing is that aliased can have any number of values.
You can put one value inside two values, one hundred values or a thousand values as you wish.
So it doesn't have any limit.
And also this can contain and mixed types of values inside integers, float's strings and so on.
So you can mix types of variables inside the collection.
There is no limitation for that as well.
So let's go quickly straightforward to a quick example of several collections.
So the first one is creation of a list.
So this is how this looks like we just create a variable.
And then we separate the words with an underline, like we studied until this point, then we do equals
and then here we put square brackets and there you go, we have our first list.
So and the next one in line is just as we talked right here, when you want to insert items inside the
list, just inside the square brackets, you can put values divided by commas and at the end closet
it with this square bracket.
All right.
So as we mentioned, let's go to the last one in line, as we mentioned, at least, can contain several
types of values inside.
So we have a list here that contains a string.
All right, contains a sorry, not a string, it's an integer and then a string and then a float all
together combined.
That's just fine.
We won't get an error for that.
And now that we know how collection looks like and we know several things about it, that he has an
endless number of cells that we can use, we can mix types in that.
So now let's try to pull out the values out of the list, meaning if we created a list so later around
the code, we would like to extract, for example, this value and use it or maybe print it.
We don't need the other values.
We just need this one, the two, for example.
So let's study.
How can we extract data from the collection?
All right.
So before we continue, I just want to say that this lecture will have two or maybe three parts as it's
a pretty big one.
I'm talking only about the lists and for the further on as well.
But this is the lecture part one of lists.
So let's continue.
OK, so how can we access a value in a list?
So basically there are two ways to access a value in the list or in other words, to extract the value
from the list.
So the first way is by accessing the the values inside the list by index so we can use.
All right, we can use the index of this value to access it.
It's supposed to be, but.
But it's important to remember that the first value would have the index to zero and not one will see
an example in a few seconds.
So just let's go over what we just read.
So if we have, for example, here, how many values do we have in this?
Let we just put it small.
We have here value.
Number one value.
Number two, value.
Number three, four and five.
So the index meaning the police.
The police.
All right.
Of the value.
This is the index.
So this will be the first place.
I'm saying literally it's first.
But as we just read right here, it will be index number zero.
All right.
So it doesn't the counting of this and then this and then this and so on doesn't start for one.
It starts from zero.
So the index of this value zero and the value and the index of this value is one and the index of these
values two and so on.
You can see right here.
So once we want to access any of the values in the list, we can access it by pulling it out, using
the index of it, and we will see in just a second how to do it.
Also, a really important note.
Once we try to access other indexes, then these we will raise an index arrowroot.
So, for example, if we try to access the index number five or index number 52 or index number twenty
seven, for example, we will have an error because we have in total only the index is from zero to
fall, then from zero to four.
So filled in and all other indexes in the world are not contained in this list.
And also, we have a second way to access the values of the list, and the second way is by negative
indexing and let's see how we do it.
All right.
So Python allows us to use Axis.
I don't allows us.
To.
Access the values.
Starting at the end of the list by adding the prefix minus to it, in other words, the index minus
one is referring to the last item off the list, which is yes.
All right.
So we have the list, by the way.
It's the same list that just copied it so it would be easier.
So we have the list.
And if we want to access to the we want access to the last item of it, we will use the index minus
one.
So once we add the minus prefix to the index, it means give me the last one.
You mean the last item of your list?
And if we use a minus two index, we will get to the before last value in the list and so on.
So let's go over with a few examples just to get the hang of it, of of access by index and access by
negative indexing.
So we have the list right here.
And let's try to print out several values out of it.
Just zoom out a little bit so we can see the list as well.
All right.
So let's try to what happens when we try to print the value in the index zero, right.
By the way?
This is the way to access values by their index.
You just write the name of your list and then put square brackets and put a number inside.
The number that you will put will be the index value.
And it will extract for you the value of the cell itself.
So once we print the name of the list.
Once we print the name of the list, by the way, I need to change it because it's not the name of my
list.
Once we take once we print the name off the list and put zero in square brackets, put zero inside,
so let's go further, let's go up and the page.
So once we print the zero index of the list, we will get an output of thirty one.
All right.
So here it will be.
Outpoured 31, and once we won the third one, so basically this is zero, this is one.
This is too.
And this is three.
So the three, the third the next on the list would give us the output.
Three, so have a look again.
This is the number zero index, this is index number one.
This is index number two and this is index number three.
If we go up, we can see it here as well.
So this is the index value.
And this is the value inside the list.
This is the sale value.
So this is on industry.
We're going to value three.
So let's go quickly on the negative ones as well.
So we have here index number minus two, meaning we have the list right here or that this is index also,
by the way, it's the same list.
So this is index number zero and also index number minus five, because when we had the minus, we start
counting counting from the last one and then the numbers go up as we go to the beginning.
So if we try to print what's inside index number minus two, we get the value of three.
So not noticed this number three index and number minus two index give us the same output you see.
So this is the index.
So this is the index minus to the values three go up.
This is the index number three and the values story as well.
All right.
So all right.
So let's go further.
And unindexed, my minus one, we get the value, yes, and index number seven, we don't have one because
our index is going up from zero to four and that's it.
So we get an index arrow because we do not have this index.
All right.
So, guys, I think that's about it dealing with theory.
So a quick overview.
We explain that we have collections on Titan.
It's a special module, a library, if you want to say so.
We have four types of collections and python list dictionaries set and tuple.
We started with the first one, which is list we want went over the definition of it and the characteristics
it has here.
We learned how to declare in your list how to put items inside the list, and the list can contain mixed
types of variables inside.
And then we'll learn how to access values using their index by using a straightforward index and also
by negative indexing with a few examples.
So let's meet in the next lecture when we try to see various examples on each arm and afterwards will
be the practice part.
And that's about eight guys.