Hello and welcome to this video.
In this video we are going to be creating a list to create a list you just need to give the list in
name you use the quotes too and then you assign the values in the list.
So you the left square bracket opens up the list.
Then you add the values in the list you separate it value with a comma.
If it's a text or a string you need to enclose it in quotes like I have done in the illustration.
And then you use the right square bracket to close the list so let's create a list.
So to create the list I'm going to be using the text editor code item and I've created a new python
file which is this file here on my desktop and I've called it my list so you can create a file a python
file and then just save it anywhere your desktop might be easier.
Like I have done and then this is the file.
So this is where I'm going to be creating my list to create a list.
You start with a name.
Always give your list a descriptive name to reflect the type of elements that the list is storing.
So I'm creating a list called animals and I'm going to set that to the different values.
So I can just say the first value in there.
I can see a bear.
A comma to separate the values add another value I'll say maybe a tiger do a comma add another one.
Let's say a lion and so long you cannot as many items as you want in the list.
I'm going to.
Let's see how it panned up let's add one more.
And the comma and I'll make this one an elephant.
So these are now elements in my list.
So to save the file just to control is on a Windows.
If you're on a Mac you do command s.
You can use what is called a for loop if you want to loop through the elements in the list and print
them out.
You can loop through them and the way you could do that you just to four and you say four X lists represent
the name of the list as X so we can say for x in animals and they had a colon and then you use the print
function or print statement impasse in the value of x.
So I chose to control s to save.
And when I open up my command prompt which is this and to access this file here which I've said I'll
just call it by its name which is my list dot P Y and our press pointer I can see here is listed all
the elements of the list.
So I'm just going to clear my console by typing in C or less if you're on a Mac you can just typing
color and that will play the console or terminal.
You can also use the print function on its own just to print the list so I can type in print and inside
the parentheses for the print function.
I just pass in the name of the list and what that would do it would just print exactly as it is.
So I do control as to save if I open up my terminal type in the name which is my list dot P why I'm
pressed into when you execute code the code will execute in the order you have written it.
So it's printing out each item first using this block of code and then it goes onto this block of code
and just prints the which is this bug block here.
It prints the entire list just the way it was created.
So that's basically how to create a list in Python.
Thanks for watching and bye for now.