WEBVTT

00:00.080 --> 00:01.040
Welcome back.

00:01.080 --> 00:03.800
In this video we're going to learn about lists.

00:03.840 --> 00:06.880
A list is an ordered collection of items.

00:07.040 --> 00:10.560
You can add, remove and access items in it.

00:10.600 --> 00:12.360
In order to create a list.

00:12.400 --> 00:18.520
Create a new variable equals sign and use this angled bracket.

00:18.680 --> 00:24.680
Inside this angled bracket, place the items you want to store inside it, separated by comma.

00:24.800 --> 00:28.360
So for example, here we have a list called fruits.

00:28.640 --> 00:33.760
This fruits list contains apple, banana, and cherry items.

00:33.880 --> 00:41.160
In order to print this list, we use print and name the list run.

00:41.360 --> 00:42.160
And here we go!

00:42.360 --> 00:42.760
Apple.

00:42.800 --> 00:43.360
Banana.

00:43.360 --> 00:43.920
Cherry.

00:43.960 --> 00:51.080
In order to access items by index, we start by starting from zero, one, and two.

00:51.280 --> 00:54.480
The first fruit, which is apple.

00:54.520 --> 00:56.520
We use the index zero.

00:56.560 --> 01:03.000
If we need to access the last fruit, we need to use negative one.

01:03.040 --> 01:06.000
Negative index equals from end.

01:06.040 --> 01:13.360
For example let me access the second fruit which is fruits one.

01:13.400 --> 01:15.600
Here I am specifying the index.

01:15.960 --> 01:17.880
The second fruit is banana.

01:18.000 --> 01:21.320
Let me access the third index.

01:21.440 --> 01:24.040
So print third fruit.

01:24.040 --> 01:26.440
And you notice that the fruits.

01:26.720 --> 01:32.920
And here I'm specifying the index inside the angled bracket run again.

01:32.960 --> 01:35.160
The third fruit is cherry.

01:35.200 --> 01:42.120
So in arrays and in lists the starting index is zero and not one.

01:42.120 --> 01:45.320
This is a very important thing okay.

01:45.480 --> 01:56.160
In order to get the length of the array or a list, we start with print length of list and we use the

01:56.160 --> 02:05.360
Len function run again and the length of list is equal to three because we can because the fruits array

02:05.400 --> 02:10.000
contains three elements apple, banana, and cherry.

02:10.040 --> 02:15.120
The length of an array is always one more than the highest array index.

02:15.160 --> 02:16.760
It's very simple guys.

02:16.760 --> 02:20.800
We created this list containing three elements.

02:20.840 --> 02:21.120
Apple.

02:21.160 --> 02:21.640
Banana.

02:21.640 --> 02:22.160
Cherry.

02:22.510 --> 02:23.510
printing the.

02:23.550 --> 02:24.950
And the list.

02:24.990 --> 02:25.390
Uh.

02:25.590 --> 02:34.790
Accessing the list and accessing the items of the list by index and getting the length of a list.

02:34.830 --> 02:44.150
Now, if we need to modify, add or remove the items fruits at index one, change the item at index

02:44.190 --> 02:44.670
one.

02:44.830 --> 02:45.910
Index one.

02:45.950 --> 02:46.950
This is zero.

02:46.990 --> 02:50.230
This is one I need to change banana to orange.

02:50.510 --> 02:52.590
So let me run again.

02:52.590 --> 03:00.950
And here the first output is apple orange and the charity banana is replaced by orange.

03:00.950 --> 03:03.950
Here I'm accessing the element.

03:03.950 --> 03:09.710
I am accessing the element by specifying the name of the array.

03:09.710 --> 03:17.470
And inside the angled bracket we specify the index and you change it by using the equals sign.

03:17.470 --> 03:19.110
If we need to append.

03:19.110 --> 03:24.990
If we need to add at the end, we need to add date for example.

03:24.990 --> 03:28.750
So apple, orange, cherry and date.

03:28.750 --> 03:36.870
If we need to remove we use fruits dot Remove and remove the orange by the value, or you can remove

03:36.870 --> 03:40.950
it by the index, but I prefer using by the value.

03:40.950 --> 03:44.790
So Apple, charity and date orange is removed.

03:44.790 --> 03:53.430
So in this way we can access, change and append and remove elements inside a list.

03:53.430 --> 04:02.030
Also, we can loop through a list by specifying for every fruit in fruits, go and print the fruit,

04:02.070 --> 04:04.830
fruit, apple, fruit, cherry and fruit.

04:04.870 --> 04:05.550
Date.

04:05.590 --> 04:13.950
This is after the modification because the last updated list is this apple, cherry and date for every

04:13.990 --> 04:14.790
item.

04:14.790 --> 04:23.990
For every fruit inside this fruits element and this fruits array, go and print all the elements and

04:23.990 --> 04:35.310
print fruit and specify the value of the element Apple, cherry and date okay so this is the basic creation

04:35.310 --> 04:36.830
of lists.

04:36.950 --> 04:44.630
How to access, how to modify, append and remove elements, and how to loop through a list in Python.
