Hello and welcome to all of my students today we'll discuss basics part two regarding if statements
in the previous lecture we have studied what are, if else, statements and also what if l if statements
where we had several conditions in the same statement.
Now is the time to expand our basic knowledge and to see much more examples and additional topics to
dominate the statement topic.
All right.
So let's go straight ahead for the first topic and let's discuss logical operators or some of you might
heard this term.
This term exists in all programming languages.
And in Python, they're the easiest.
So you got that for you.
It's the easiest on Python.
And why is it easy?
Let's see and let's begin and see.
All right, so logical operators and Python are displayed really easy because they just as in plain
English, in other programming languages, you use special characters to implement the logical operators,
both right here in Python debut, as in simple English.
In our lecture, we'll discuss only two of them.
All right.
So before beginning, I just want to, like, get a quick reminder that we have seen in the previous
video, simple statement, for example, if it's bigger than a.
Then print, for example.
Brent.
Success, right?
But now we're going to have two conditions in the same if statement and let's see, how can we handle
it with the help of these logical operators.
So, for example, we have here is bigger than eight.
And I'm going to write here and.
All right, y equals no, let's do it.
Why smaller than five.
Right.
So and right after we have here else and we have here, as always, the default accent point.
Yeah.
So what do we have here?
Actually we have here the first condition, which is X larger than eight and Y small.
Smaller than five.
Right.
So we have also the logical operator and here.
And what that basically means is we need to sorry, we need two conditions to be true for the code under
if statement to run.
So so we could run this code.
We need both this one and this one to run to be true.
All right.
So, for example, if we have like X equals 10, but why is also equals then.
So this will not run because the condition says and this means that both this one and this one should
be true in order for this go to run if one of these are false.
So this gold won't run and the only thing we're going to have is default exit point.
All right.
So it's pretty easy.
It basically means that both this one and this one should be true.
But in our case, Y equals stands.
So this one will be false and the output of this whole thing is going to be the default exit point.
All right.
So what if we'll have not or not and but will have and or here.
All right.
If we have the logical operator or right here, this means we need just one condition to be true for
the code under if statement to run.
All right.
So what that means is this one is true, right.
But this one is false.
But it says or here the logical operator or and this means one thing only that it's enough for one condition
to be true for this one, for example, for this code to run.
So the output of this whole thing will be all right.
Success because it's bigger than eight is true.
So we're going to go with this flow of gold and not this one.
All right.
Pretty easy.
So I actually showed you an example in the last seconds, but let's see another example just to make
this like sit tighter in our brains, right.
So we have here these variables.
Eight can be five and C2.
And let's see example.
No example.
No, it's not a number, for example.
So A is bigger than B, A bigger and the B2.
And then we have a smaller than C, a smaller than C is false.
Right.
But we have the all logical operator here and that means only one thing.
This sentence will be printed because once we have the all logical operator, even though this is true.
But this is false, right.
This one is false.
It doesn't matter because all logical operator says that it's enough for one of them to be true in order
for the code under the IV to run.
Right.
But in the other hand, in this example right here where we have this same condition and we just saw
that this one is true and this one is false, we have the logical operator and here and means that both
of them should be true.
And this is not happening right here because this one is false.
So once we have this block of code, we're going to run.
The code will run.
None of them.
True.
All right.
Because this one is false.
And once you have the analogical operator, it's straight.
It goes straight to the default exit point, which is else.
All right.
I think it's not really tough topic, because once you understood in the previous lecture, what are
if statements like simply statements.
So this is an extension for the basic knowledge.
It's nothing special here.
Just a small extension to the previous lecture.
Stipek.
All right, so from here, let's go to the next topic of this lecture.
What is the difference between equals and double equals?
All right.
So as you might notice, one, when I started to writing the example here, I like the one that I raised.
I wrote Equals Equals.
And then I raised it.
Because we're going to talk about this right now and explain the whole thing.
All right.
So what is the example between these two?
All right.
So it's very simple.
We're already familiar with a single with a single equals mark, and we use the equals single equals
mark to assign a value to a variable.
For example, X equals five means X equals five.
Surprise.
Right.
So this we already know, but we can't use it, for example, in an F and do like this.
All right.
We can't do this because Biton knows that the usage of a single F is to put a value inside a variable.
And once you do this, he doesn't know what you want from him.
He doesn't know what to do.
All right.
So for that python who invented Python and invented the double equals Mark.
And once you apply it all right, once you apply the double double equals Mark.
All right, when you use the double equals assigned to ask if two values are equal, OK, and what that
means is usually it's used in the statements and for example, you have your eggs, double equals five
means.
Does X equals five.
Right.
Because if you use it in if.
He goes like this, and what that means is if X equals five, then do something right here, right then
do then if not, go to else.
Right.
So we already familiar with this guys, right?
With this one and this one and both of these.
Right.
We're familiar with them.
But now we also have the double equals Mark to use also a comparison for equals.
Right.
So.
You can see the same example right here, and you can just put the value five inside X and then ask,
does X equals five?
All right.
And then we have the code on the left and the cons are under the else, as we already know.
All right.
So you can see the difference here.
Here is the statement here.
It's the sort of question pretty easy.
This is why it's very important to see you all the theoretical lectures, because if you just encounter
it spontaneously in a cold or on way online somewhere, it looks like threatening because you're starting
to see this sign and this sign and you starting to get confused.
But once you break it down to two simple problems and you explain it for simple examples, so the material
sits in your head tight, and then once you understand it, it's very, very easy.
And the secret is examples in practice, as I always say.
All right.
So from here, we're going to now handle the last and I can say the difficult part, it's a little bit
more difficult than the two topics we just discussed, but already familiar with the term nested.
And we've seen it in dictionaries.
We know what's in the dictionary.
It's once we have cell inside a cell.
So basically and if statements, the nested term is pretty much the same.
Right.
The nested means once you have something inside, something.
Right.
So we have seen many example of all examples of you statements.
But what about having an if statement inside any statement?
Right, any statements we can nest them one in another, meaning if some statement came up true, right?
Only if it came up true, then go inside another if statement, which can also be true or false.
So before looking at the sketch, this basically means that, for example, you see this example right
here.
So here we have Anif statement.
And instead of just doing as some action such as this print in here, instead of this marked line,
you just insert another if in the alse.
All right, right here, instead of this line, you just insert another if and else.
All right.
So from here you can see the quick sketch.
I think we should first go over the sketch, see the logic's and right after go over the example here,
which explains it better.
All right.
So first of all, you just start the class or module.
You just run it and then the cold encounters the first if statement.
All right.
And then your statement could be false and then the code under alse would run as always.
As always.
And once the statement comes up boolean true.
You came up, you you get two additional F statement which which this one is the nasty statement.
Right.
This is the nested eve statement.
And right here you can have either another false or true.
And if you have a false here, so run the code inside Neston else.
All right.
And once this one is true.
All right.
Run the code inside nested if.
All right.
So once it's false, run nested else.
And once it's through from the nested under the if.
All right.
Let's see a quick example for this sketch right here.
So let's put one variable, which is H equals 30 and another string variable.
Gender equals male.
All right.
So right here, we're running the code from top to bottom and the code sees this variable and this variable
comes up with this if statement.
And right after this, if you can have two options, you already can notice that this one is marked
with blue and or gray.
Yeah, it's blue.
And this one also with blue means this is the parent if statement and this is the parent P&L statement.
So right here we can have two options if this one is false or if the age is not bigger than 20, for
example, it's ten like that.
All right.
The the is the age bigger than 20, for example, is the false.
Then obviously, as always, we will go to the default import and print age is not bigger than in our
case right here.
Ten.
All right, but No.
20, still 20.
All right, so if this one would be false, would run this cold, as we have already studied.
Right.
But once we put like 30 here, for example, and then 30, which is the age is bigger than 20, what
will happen?
What always happens, the cold under the if would run and what is the cold under the if all the chunk
that I just marked, not just a single line, everything under the F would run.
And as we know we go from top to bottom.
So we covered this and this lot less line was true.
And then we go inside one line deeper and right here we can see another if.
Right.
We can see another if you're if gender equals male.
And this one, my friends, is a nested if.
All right.
You can forget about this line and forget about this line.
That doesn't matter at this point.
I'll need this great part.
The inner nested part is Metters.
Now, once we have passed this line, you are here.
Only this thing matters.
Now, right here we also ask us we also ask the code is gender equals male.
In our case, gender equals male.
Right.
It's a true statement.
So right here, this one is true.
So what will happen?
The code under the if as always, would run age is bigger than twenty and the gender is male.
All right.
So this would happen, and for example, if we have.
Female here, yeah.
Then again, we run into record and then we're going to run this one and then we're going to go here,
and if gender equals the male, it's a false right, it's a false value because the gender equals female
right now.
So it's a false.
So what will happen?
Eventually, this gold will run and is bigger than 20, but gender is not male.
All right.
It's pretty easy.
You have the first first statement right here.
It could be false and it could be true.
And if it's true, then the inner if statement could be false or it can be true.
Right.
It's a negative statement.
Very necessary.
From time to time, you could see that our progress is getting faster and we're learning some really
cool stuff and are beginning to be deeper and deeper.
And it's only makes me happy because each lecture that you study, you become more professional developers.
And eventually we're going to combine all of these terms that we study and try to resolve assignments,
all of them together, variables, collections, statements for loops in the future and all together
as a symphony.
All right.
We're going to get to it.
We were waiting for us a project by the end of the scores to use all of these terms all together.
And once you can make it like play as a symphony, you can give yourself a medal of a developer ninja.
And this is basically my goal.
And once you get there, you can easily go to interviews and pass them, because once, you know, to
code once you will practice all this practice that I'm giving you.
And also we will be helping you with the final project.
And once you build the final project, you can easily go to interviews and nothing that will ask you,
you would not know.
You can answer all the questions.
Right, because if you practiced it, they're asking you asking you, for example, what's the difference
between is a list and a dictionary is a dictionary and indexed how to build a nested if statements so
you can shoot the answer answers real fast and show yourselves as professionals.
All right.
So end up in the next lecture will continue learning if statements more deeper and then we would have
a practice part.
I think that in the next video I will show you these examples, especially the nested if statements,
how it works in the code.
So you would get into our minds much easier.
And that's about Rigi.
So stay tuned and stay strong and we'll go through this together.
I'm always here for you for questions.
You can personal messaged me by email and I'm here for you.
Also, you can visit my Facebook page, which is ninja developer, and ask questions over there and
that's about it.
I will see you in the next video.