0:00
Hey everyone, welcome back to this
0:01
channel. This I Raj Lakmi Singum. So
0:04
today we are diving into something that
0:06
looks small but is super powerful in
0:08
Python which is logical operators. These
0:11
are the words that help Python make
0:14
decisions almost like the brain behind
0:17
your conditions. We have got three of
0:19
them. One is and operator and the other
0:22
is or operator and the other is not
0:27
Don't worry if this sounds confusing
0:29
right now. I'm going to make it super
0:32
simple for you with real examples. Let's
0:35
start with and. Think of it like this
0:37
like you are allowed into a party only
0:40
if you have an invitation card and
0:43
you're wearing the dress code. Both
0:46
conditions need to be true. If even one
0:48
fails, sorry, no party for you.
0:52
So in the same way like for example x =
1:08
and if x less than y and
1:23
Both the conditions are true.
2:11
So what's happening here? X value is
2:14
five, Y value is 10 and Z value is 15.
2:17
If x less than y is 5 less than 10 true
2:22
and y less than z and y is 10 is less
2:25
than 15 true. So it will obviously print
2:30
what I want you to pause at this moment.
2:32
Please trace it yourself and check
2:34
what's the output. If possible you can
2:37
comment down below. I'm going to check
2:38
it for sure. So here the condition if
2:42
this condition is true what happens both
2:45
conditions are true. Else maybe any one
2:48
of the condition is false. So that is
2:49
why it is coming to the else part. So
2:52
that is what we are letting user know.
2:55
So is five less than 10? Yes. Is 10 less
2:59
than 15? Yes. Both are true. So the
3:02
answer is both conditions are true.
3:06
But if even one of them was false then
3:09
Python would immediately say no at least
3:11
one condition is failed.
3:14
So this is all about and operator.
3:18
Now let's talk about or operator. This
3:21
one is way more chill. Imagine you're
3:24
buying a game online and you can pay
3:27
with a credit card or PayPal.
3:32
As long as you have got one of them, you
3:34
are good to go. You should use either
3:37
credit card or PayPal. That's it. Like
3:39
for example, if you give
3:49
and has card I'm creating one variable
3:52
called has card which is nothing but
3:56
credit card true you can create variable
3:59
something like this as well according to
4:01
the requirements so it's actually a
4:04
smart way to create a variable based on
4:06
the requirements and even the developer
4:08
will understand that this variable is
4:10
used to check whether user have a card
4:13
or not? So it is actually self
4:16
representing its meaning. Okay. So if
5:08
cannot make the purchase.
5:25
So what's happening here? So Python
5:27
checks the user age and it will check
5:29
whether age is greater than 18 or not.
5:32
So if this condition is true, then this
5:34
statement will execute. It will not
5:36
check whether this condition is true or
5:38
false. As soon as this is true, once
5:40
this is false, this condition is false,
5:43
then the program comes here, checks
5:44
whether this condition is true or not.
5:46
If this condition is true, then it will
5:50
print the result. Okay, if any one of
5:53
these two conditions, if any one of it
5:55
is true, then it will print. In this
5:58
case, the age is 25, age is greater than
6:01
18, true, then it will directly print.
6:03
And sometime in some cases, maybe for
6:05
example, age is 16. So it comes here it
6:08
will check it is false. So now it will
6:11
come here it will check it is true. So
6:13
then it will execute this
6:16
even if the second condition was not
6:18
true the or would still let it pass.
6:20
Basically if at least one is true then
6:22
Python says cool let's go.
6:27
Okay now let's talk about the not
6:33
This one is like a rebel. Whatever the
6:36
condition is, it just flips it. If yes
6:38
is no, then no. No means then yes.
6:44
If Python thinks it's true, not says
6:47
false. If Python thinks it's false, then
6:56
there is a variable called it is
7:03
and we gave it false.
7:25
It It is sunny today.
7:46
So here we created a variable called it
7:49
is raining and this actually will check
7:53
if there is no rain. So if there is no
8:00
So if not false is nothing but it's
8:03
true. So this condition is true then it
8:07
will say it's sunny today.
8:15
Not false is nothing but true.
8:18
See the logic here. So if not false that
8:22
means if you add not besides the false
8:26
then false becomes true. If you add not
8:28
besides true then it will become false.
8:32
So in the same way this is false and you
8:34
added not to it so it became true. So if
8:37
this condition is true then obviously
8:39
this statement will get executed. So
8:41
that's what we are seeing as output.
8:45
So here it is raining is set to false
8:49
but we used not it is raining that
8:52
basically means not false which is
8:54
nothing but true. So, Python prints it's
9:00
Like for example, if you give
9:05
this time, so it is raining. But if you
9:09
give not true, then it will be false. So
9:13
it comes to else part and it will print
9:16
it might rain here. You got my point?
9:18
Not true is nothing but false. So it
9:23
So that's what happening here.
9:27
So that's the magic of logical operators
9:30
and or not and both need to be true or
9:36
at least one needs to be true
9:39
and not it will flips the condition true
9:41
to false true true. So these tiny words
9:45
are going to be your best friends
9:46
whenever you start writing conditions in
9:48
Python. So I want you to make sure
9:52
practice more uh exercises using these
9:55
operators so that you will feel it handy
9:58
so that you can use it freely according
10:00
to the requirements. All right friends,
10:03
I hope that made sense and you feel a
10:05
little more confident with logical
10:07
operators now. And if you need more
10:10
exercises, just comment down below. We
10:12
are going to make more exercises as
10:14
well. And remember coding is just like
10:16
learning a new language. You don't
10:18
master it in a day, but every single
10:21
step you take makes you better. If this
10:24
video helped you even a little bit, do
10:26
me a favor, hit that like button,
10:28
subscribe if you haven't already, and
10:30
maybe share it with a friend who's
10:32
learning Python, too, because learning
10:36
is always more fun when we do it
10:38
together. I'll see you in the next one.
10:40
Until then, keep coding and keep