Hello guys.
Welcome back to another class of our course about Python.
So until now we talked about a lot of interesting things which are variables we talked about data that
you can store in your variables.
We created apps to put everything together.
And until now you have small but pretty good knowledge of python.
So in this class we are still going to continue talking about data up data manipulation.
So my goal right now is to show you another way that you guys can store your data so you can store your
data into a variable so we can store in number a string or a boolean instead of a variable.
But let's say you want to store a bunch of data at the same place.
So this is where lists come into play.
The list is simply a variable where we can store more than let's say one data.
So let's say for example let's take a variable so I'll write down here variable one and the variable
one.
Let's say I want to store a string instead of it.
So let's say I store Apple so you can see my variable number one has only one element in it.
So it has only one string.
But let's say I want to create a list.
So in this case I'll write.
Don't list one.
It starts the exact same way but right now to write down my list what I'm what I need to do is open
up those special parentheses and I can start writing down the all the all the other ones that will be
my list.
So let's say I have apples I have bananas I have.
And then this
and I have melon.
So fruits.
All right.
So as you can see if for example I decide to print the whole list.
So in this case it will be list 1.
So what will happen is that python will print the whole list as you can see I have my four of my four
elements right here which is apple banana and on us and melon.
But let's say right now I want to work with my list and I want to print only one of those elements so
in this case let's say I want to print only Apple.
So the way I explained you guys Python works Python well in this case python will use indexes but how
indexes work is very simple.
The first element is always the element 0.
So in this case Apple will be equal to zero.
Banana will be equal to one and S will be equal to two and million will be equal to three.
So let's say I want to print the first element which here will be the element 0.
So how I will do this I will write down my friend function.
Then I write down the name of the list for the variable that I want to print.
And in the case that if it's a list I will still open up my parentheses.
And in this case I will select the number zero.
So let's say I want to print Apple so I will simply write down zero which is the index value of Apple.
And as you can see I just print that out.
Apple if only print out banana in this case I will simply write down number one and I printed test and
see it writes down banana all right.
So right now you know exactly how you can select the right value to print.
So let's say for example Apple banana or us.
You simply write don't print you write down your list.
So in this case list number one and you select the index value that you want to print.
So you want to print number one number zero one two three.
Next thing let's say for example right now that you want to modify what's in here.
So in this case for example we have Apple we have banana and we have a..
But let's say I want to change melon by.
I don't know avocado so in this case what I will do it is very simple.
So I write down my list one and I will open up my parenthesis and then this case I will select the index
of melons or melon will be the third index.
I write down equal.
And by and I write down by what exactly I want to change melons so in this case I want a change melon.
But full cattle then when it's all done you can simply print this let's say in this case I print this
so list
and as you can see here it all changes.
So I have apple I have banana.
I have an illness and I have avocado instead of melon because I just changed my Yeah well my my element
right here which is melon.
I change it by avocado.
I can't do it on multiple elements so let's say for example I want to change the element number two
as well so you can just write down list.
So list one and I changed the element number two which is unless I can change it by I don't know to
me.
So in this case I'll change you by to model and if I print list one once again you'll be able to see
apple banana to me you and avocado.
So as you can see guys it's very very simple to use.
So this is a way that you guys can print.
You can print elements so you can see it's very very simple too.
Well very simple to work with lists in the basic ways.
If you want to select an element and if you want to modify an element.
All right.
Another thing that you guys can do with lists in this case would be selecting only one of the elements
or multiple elements but not all elements.
So let's say for example right here I have more than four elements.
Let's say I want to have.
So I have apple bananas and a nice melon strawberry
and other
right.
And right now I only want to have the element number let's say two.
So banana.
So how exactly I will do this exact same thing.
So simply I will print.
So I use my print function I write down list number one.
So in this case list number one and I open up my special parentheses and I write down so what I said
is I want my banana.
I want my N.A. so banana is the number one and an S is number two in our Python index.
So what I want to write is from 1 to 3.
So what's going to happen here is that python will give me will return the number one and the number
two but will not return me the number three.
So let's say I print everything right here.
So I have my banana and my N.A. if I want for example to print that my banana my antennas and my melon.
In this case is going to be from 1 to 4.
And if I print it.
Well as you can see I will have banana and an S and melon.
But let's say I want to print everything but not the apples.
In this case I can just write it down like this.
So it's gonna be print list one and two points and they leave it empty as you can see it's gonna print
absolutely everything.
If I start printing from an n as well in this case I can just write them too because it's gonna be index
zero index 1 and index 2 and I start to print from index 2 and index 2 is included so I'll have an A.M.
melon strawberry and other so you can see this is a basic manipulation of lists and what exactly you
can do with it.
And as you can see it's not that hard to do and it's not that hard to use.
Well as I explained if we summarise absolutely everything difference between the list and a variable
is that a variable will have only one element in it.
It could be a string could be a boolean it could be a number but in the case of a list it's a it's absolutely
different.
You can have all the trees so we can have numbers boolean and strings and what is school is that you
can work with all those at the same time.
So at the same time you can select one of those and you can work just with this only element.
So right now you know the basics of lists in the future we are going to talk about more advanced functions
about all those lists as well.
So that's it for the sports guys and see out in our next class.