0:00
Hey friends, welcome back to our Python
0:02
journey and today we are going to go
0:03
through module four. We are going to
0:06
talk about one of my favorite topics
0:07
which is lists and Python.
0:11
Why are lists so cool?
0:18
Well, because they can hold anything.
0:20
Could be numbers, strings, even other
0:26
If Python is that flexible.
0:29
So what exactly is a list?
0:35
So think of it like a shopping bag. You
0:38
can throw in apples, bananas, milk, and
0:41
maybe even a smaller bag with cookies
0:45
So that is actually something like a
0:47
Python list. It could be ordered. We can
0:51
change it and it can hold different
0:53
types of items. Maybe list inside the
0:56
list or as well. like if you see here
1:02
So let's start with the syntax of the
1:04
list. So to make a list you just have to
1:08
use the square brackets and separate the
1:10
items with commas. Let me show you like
1:13
for example numbers. I just create I'm
1:16
creating a list. So now at this point
1:19
Python is thinking it as a variable but
1:21
later when you give list.
1:30
Okay. Now you see Python is taking the
1:36
And now when you print numbers
1:41
it will print the list.
1:51
So to make a list you just have to use
1:54
the square brackets and keep the items
1:57
inside the list separated with commas.
2:03
And you can create even fruits
2:07
list here. Just create it. So always
2:12
fruits are you know you'll give string.
2:28
And you can create mixed list like uh
2:35
where you can keep everything like you
2:46
any boolean data which is either true or
2:50
false. And you can also keep list inside
2:54
So you can add multiple items at once.
2:57
And when you print this, print mixed
3:09
So it will just print everything you
3:16
doesn't mind. It can, you know, add the
3:18
numbers, the string, the boolean data,
3:22
true or false, and a list as well.
3:25
Sorry, my throat is really bad today. A
3:31
So now, how do you grab something from
3:34
your list? Like in order to print, I
3:36
just want 10 from this one. How do you
3:39
do that? Well, for that we use a concept
3:42
called index. In Python, the counting
3:46
starts from zero. Not just in Python, in
3:48
any programming language. when you're
3:50
giving anything in the list or it could
3:52
be an array in other programming
3:54
languages. So you always start with zero
4:02
2 so 0 1 2 3 0 1 2 3 4 something like
4:10
So in order to get the first item you
4:13
have to just give mix the list of zero.
4:17
So when you do that it will just print
4:25
See and when you give one
4:30
then it will give you the second item
4:36
So this is the second item. So zero
4:40
think of it like a memory. It is saving
4:43
it as a zero memory and the first one
4:46
and the second one and the third one.
4:52
So the position of 10 is from my list of
4:55
zero. The position of Python is one and
5:02
So what if we want the last item? You
5:10
So then it will just give you the last
5:13
item. But now I know that there are four
5:16
items in this list. Sometimes I don't
5:19
know how many items are there in the
5:20
list to get the last one last position.
5:24
So what I can do is I can just give
5:26
minus one to get the last position when
5:29
I don't know the length of the list like
5:32
the size of the list the number of items
5:35
in the list. Then if I if you just give
5:37
minus one then it is going to get the
5:39
last one for you. If you give minus2
5:43
then it will give you the last second
5:45
one. It's like you're telling the Python
5:48
hey Python get me the last item from the
5:51
list last second item from the list.
5:56
So the positive numbers count from the
5:59
front like 0 1 2 3 and the negative like
6:02
if you want from the last one then it
6:04
will be min -1 -2 you know minus 3
6:08
something like that don't worry if you
6:10
just if you practice more then you're
6:12
going to you know get more idea on how
6:16
So why lists are amazing? I could say
6:20
because they keep order like the items
6:23
stay in the order the way you put them
6:26
and they are mutable. It means you can
6:28
change or add or even remove the stuff
6:31
from the list and they are flexible. If
6:34
you see they can hold anything. If you
6:37
see in other programming languages like
6:39
for example if you see arrays so there
6:42
you just have to give numbers you just
6:43
have to give strings you just have to
6:45
give boolean something like that but
6:48
here you can give whatever the data that
6:50
you want and it will you know take the
6:52
values flexibly according to the needs.
6:56
So here we have actually saw that lists
7:01
are actually a collection of items that
7:03
you keep in a you know brackets in a
7:06
square brackets separated with comma
7:09
something like this. Okay, we can change
7:12
them, we can add, we can remove the
7:14
list. And why they are amazing? Because
7:17
they follow the order. The order that
7:19
you give element one, element two,
7:21
element three. And it will start from
7:24
zero. The position of the first element
7:27
in the list starts from zero. And it can
7:31
hold any data type, number, strings,
7:34
anything. So this is how you will create
7:37
numbers in the list. You can create
7:38
fruits in the list. You can create
7:40
everything. You can keep a number, a
7:42
fruit, a boolean and even a list.
7:46
So it can access and we can access
7:49
elements by index which is nothing but
7:52
we are just going to give the position
7:55
like imagine that there is a box holding
7:59
in zero and one banana is holding in one
8:02
and orange is holding in two and
8:04
strawberry is holding in three something
8:08
And when you want the last item then you
8:10
will just do minus1 in the brackets.
8:14
Then it will give you the strawberry as
8:17
And in the next video we are going to
8:19
work on the list built-in functions. So
8:22
it flows directly after this one. Yeah.
8:25
Don't forget to like, share, and
8:26
subscribe. In the next video we are
8:28
going to work with list built-in
8:29
functions. See you in the next one.