0:00
Hey everyone, welcome back to our Python
0:02
beginner series. So today we are going
0:04
to check the presence of an element in
0:06
the list. In the previous episodes, we
0:08
have gone through what is list and some
0:10
exercises regarding the list, its
0:12
built-in functions and everything
0:14
related to the list. If you guys missed
0:17
that episode, I want you to go back and
0:18
check that and come back here and start
0:20
continue learning from here.
0:23
So here we are going to check how to So
0:27
here we are going to learn how to check
0:30
if a number exists in the list or not.
0:33
So here's the idea. We'll ask the user
0:36
to type in a list of numbers. Then we'll
0:38
ask for another number and finally we'll
0:40
check if that number is inside the list
0:46
Well, it is actually easy. But this
0:49
small concept is used all the time in
0:54
All right, let's write this code
0:56
together to understand step by step.
1:30
and dotsplit. I'm separating it right
1:32
away using the split method. It's
1:35
separated with comma. Okay.
1:47
for the number what number the user want
1:54
Okay. So number equal to input.
2:21
So here is where the actual game begins.
2:24
So blindly type whatever I'm typing
2:26
here. Later we'll understand what's
2:28
going on. So check using
2:41
in list input. If there's a number in
3:14
And also I'm using f strings. I have
3:17
already made videos multiple exercises
3:19
on f strings. So print f string
3:39
So we took input from the user. For
3:41
example, I give 1 2 3 and then I give
3:46
the number that I want the program to
3:47
check whether it is there in the list or
3:49
not. Like for example, three. If three
3:53
is in the list, if it if this condition
3:57
is true, if three is in the list, then
4:00
it will print that the number three is
4:02
in the list. Like for example, if I give
4:06
five as input and the five is no, there
4:10
is no chance that five is in the list
4:12
because we didn't give number five in
4:14
the list. Okay. If the five is in the
4:17
list, then it will check if five in
4:19
list. No, then it is false. Then
4:23
automatically it will jump here and it
4:25
will print that the number five is not
4:29
So this is what going to happen.
4:40
1 2 3. Three. The number three is in the
4:55
The number five is not in the list. So
4:57
this is what happens. So what happening
5:01
here? If five in list like in order to
5:05
check whether the number is whether the
5:07
element is in the list or not you just
5:09
have to simply use that if number in. So
5:14
you have to use in in what in list. So
5:17
in list if there is a number or not you
5:19
are asking the program.
5:22
So that is how you will do it. So this
5:24
is just simple syntax to you know
5:27
remember that is why if you know English
5:29
then Python is really easy for you to
5:31
understand. It is very simple you see if
5:34
number in list even in English or even
5:37
when we ask ourselves we obviously use
5:39
this syntax in our mind to check in the
5:41
program. So it will be even easy for us
5:43
to you know remember even when we are
5:47
you know during tracing or when we are
5:50
running something when we want to see
5:52
what's going on there this syntax is
5:55
really easy to remember so that is why
5:57
Python is really you know fast and easy
6:00
to learn language I could say
6:04
so I want I will explain once again so
6:06
when we use dotsplit so it takes the
6:09
input like 1 2 three and turns it into a
6:13
list of items like this.
6:45
Then we ask the user the number to
6:48
check. One more number to check.
6:50
Finally, we use a simple if else
6:53
statement. If the number is inside the
6:55
list, then it will print yes, it is
6:57
there. Else, no, not found.
7:04
And that's it. We just built a simple
7:06
program that checks if something exist
7:09
inside a list or not. Believe me, this
7:11
is kind of the logic you'll use a lot as
7:14
you get better in Python. All right,
7:16
friends, before you go, let me ask you
7:18
this. If this tiny program made you
7:20
smile even once, or if you learned
7:23
something new today, imagine how much
7:25
more you learn if you stick around. So
7:28
go ahead, hit that subscribe button like
7:30
you're pressing enter in Python. And
7:32
don't forget to turn on the bell
7:33
notification so you don't miss the next
7:35
program we build together. Keep coding,
7:37
keep exploring, and I'll see you in the
7:39
next video. So happy coding.