0:00
Hey everyone, welcome back to this
0:02
channel. Well, this I Raja Lakmi Singum.
0:04
If you're just starting out with Python,
0:06
today's topic is going to be super
0:08
helpful for you. We are going to talk
0:10
about membership operators. The little
0:13
keywords that help you check whether
0:16
something exist inside a list, string,
0:20
or any collection in Python. Don't
0:23
worry, we'll go step by step and use
0:25
examples that are really easy to
0:29
So, Python gives us two membership
0:31
operators which are in and not in. Let's
0:40
Imagine you have a basket of fruits and
0:43
you want to check if an apple is inside.
0:46
So, that's exactly what the in operator
0:49
does in Python. It checks whether
0:52
something is present inside a list or
0:55
string or any collection. Like for
0:58
example, if we create a list
1:17
Now we'll give a condition if three in
1:51
number three is not present
2:02
Okay. So here Python if you give if
2:07
three in my list. So, Python looks
2:09
inside this my list and it will check
2:13
whether the list have three or not. If
2:17
the number three is present then that
2:20
means this condition is true because you
2:23
see three is present in the list. So, it
2:26
will just print this number three is
2:36
See this is what for example if you give
2:52
number 10 is not present in the list
2:54
because we don't have number 10 in the
2:56
list. So it will check it will jump to
2:59
my list. It will check whether the
3:01
element is there or not using this in
3:03
operator and then it will give us the
3:07
And second operator we have is not in.
3:12
Now let's uh flip this situation like
3:14
what if you want to check that something
3:17
is not in the list or any string.
3:21
So that's where Nin comes in. Like for
3:37
just create a variable called phrase and
3:52
now we will check whether the if
4:14
is not in the sequence or sentence.
4:32
it'll be opposite right so the letter x
4:43
that's it so what's happening here here
4:47
Python checks if the letter X inside the
4:51
phrase or not. So inside this hello, how
4:54
are you? So since you see X doesn't
4:57
appear anywhere, so the condition is
5:00
true and it prints the letter X is not
5:07
So basically not in is the opposite of
5:16
See the letter X not in the list.
5:35
see the letter H in the sentence. Not in
5:39
is opposite of in. So I already told
5:41
you. So use in when you want to check if
5:45
something exists in a list or string or
5:48
collection and use not in when you want
5:50
to confirm that something does not exist
5:53
there. It's like asking is this
5:56
ingredient in my recipe or no it's not
6:01
So this is what about in and not in. All
6:05
right friends that's it for today's
6:07
lesson on membership operators.
6:09
Remember, these tiny operators can save
6:12
you from writing long loops and make
6:14
your code so much cleaner and smarter.
6:17
Now, before you go, if this video helped
6:19
you understand things a little better,
6:21
do me a small favor. Hit the subscribe
6:24
button, tap the bell icon so you'll
6:26
never miss out on future videos where we
6:29
make coding feel easy and fun together.
6:32
And hey, drop a comment telling me what
6:34
you'd like me to cover next. I'd love to
6:37
hear your ideas. Until then, keep
6:39
practicing, keep smiling, and happy