Welcome back.
So in this lesson we should take a look at lists one way to do this.
I'm going to create a new project or a new script by coming by her have new and then I'm going to press
control and as other same time and call this number two and to underscore list that's going to be the
name of this one.
Once that is done we can close this old one and I'll expand a bit.
So in Python lists are very similar to the arrays we are used to in things like C language Java and
C++.
We can append elements to list we can.
It's Rachel about them and do all sorts of things with list.
Let's get started.
So to declare lists let's say I have a list that I call my list.
I can simply see my list of course this this is how we declare a list so we can see in my list is this
and to add an element to runtime lessee I have this list it's existent some way in code line number
one and line 200.
I want to add an element to this list.
I can just see my list dot append
and then I can add a number that say I'd in 56 to it and let's see our press control s and actually
let's print so that we don't print all by that I can see print and to print to access to the element.
So you can see this is the first element added to the list.
Therefore this is going to be at index number zero of the list so I can just say print my list and then
over here I pass index number zero.
So press controls to save.
Click Run Run module.
And as you can see it's returned to 56.
So indeed with appended this and we can append as many elements as we want.
I can see my list dot append three or four and then I can you can continue by seeing my list append
then 67 Exeter.
Right.
So then we can change and I can come over here and see.
Show me what is at index number to click over here to run click OK to save and run and then indeed index
number two sixty seven course this index 0 Number 1.
Number two in the same way we could iterate over the element in the list and we can come down here see
for a for loop is for our simple n in python you a fourth and then you create an iterator let's give
our it's written name x x is going to iterate what do we want to iterate through we're going to iterate
through a list called my list as we declared up there.
So as simple as 4 x in my list and then call on no one can come here and say print x.
So what's going to happen is just by using my list python will get a length of this list and it's going
to know that the list has three element to it X is going to start with x 0 x 1 and then x 2 therefore
it's going to print was that you know x 0 X1 and then x 2.
Exactly.
So let's see what this would give us.
Come over here you can see it's given us given us let's see it's given us fifty six four and then six
to seven less less clean this less comment this out with comment with the no sign or the harsh sign
in Python so you can just comment this out because this is confusing our resort so once that is done
we can run and see and indeed with iterate through the list very simply just by using X and we didn't
even need to see for X and we need to see things like the length of the list just by using the list
name.
Python gets that length and its way through and just by using X we didn't even have to say print.
You know my list index X in the standard to see what we may have to do would be to say print my list
like this and then pass expert over here index X in Python.
We can simply say for X this is the simple way to iterate through a list for x in my list is going to
automatically get you use x to represent each index and then print out the content.
So this is a like this index number zero number one.
Number two a simple cluster.
So this all there is for list.
This is the basics we're going to be using these things and all you need to know about this this.
Showing you.
So this or there is for this very short lesson if you have any questions as usual just send me a message
or leave it in the questions area and I shall see you in the next lesson.
Have a good day.