Welcome back and let's talk another term logical operators and they're very very useful when it comes
to conditional logic.
Let's have a look.
Logical operators are.
Well as a matter of fact you've actually seen them before and is a logical operator or is an logical
operator.
It allows us to perform logic between two things.
What else is a logical operator.
Well let me listed out for you.
We have greater than less than equal to let's actually use them.
And an example is for greater than five well if I print this.
What do you think will happen.
Shouldn't be a surprise.
That's false.
Four is not greater than five.
This is a logical operator that you may have seen a math class.
If I do the opposite is for less than five.
That makes sense.
That's true.
What about is for equal to 5.
If I run this I get false.
Now why did I use two equals here.
Why not just do this.
Well if I run here I get an error syntax error keyword can't be an expression it's because remember
equal is what we used to assign to a variable.
Right.
And if you remember I told you that a variable in Python can start with a with a number.
It has to be a letter or underscore so when I do this it's going to error because the interpreter is
going to say hey I'm trying to assign a variable for the value of five.
And while that's not really allowed.
So we use double equals to tell the interpreter Hey I'm not assigning a variable here.
I want to compare things and we can compare different things.
I can do.
Hello equals to Hello equal to true.
What if I do a is greater than B I get false.
Now why is that this.
I want you to Google on your own and figure out why is a greater than B.
What if I do a.
Is that greater than capital A That's true.
This is this is interesting and this is actually quite an interesting reason.
So I know I know it's easy for me to just give you an answer but I want you to practice googling this.
And the reason I'm not giving you an answer is it's also because it's not very important because most
of the time you want to make code that is easy to understand and understandable you're most likely using
greater than and less than with numbers.
So if you see something like this in code.
Well you wouldn't know what's going on.
What is this person trying to compare why are they doing is lower case a greater than capital A it's
not something that you see very often but the reason you get this expression is quite interesting.
So I do recommend you Google Google into it.
Like I said I'm a strong believer in not holding your hand the entire way.
I know so far the videos up until now have been quite easy especially if you are an experienced programmer.
But as we progress you'll see that after this course you need to figure things out on your own.
And my job is not to just handhold you the entire way it's to develop the skills in you to become an
employable programmer.
So I hope you bear with me as I just give you this little challenge.
All right.
We want to bid on a tangent so let's bring it back can I do things like this is one greater than two
or you know what let's do less than two and less than three and less than four.
Will this work.
Well of course it will.
It's just an expression rate that we're evaluating and all of this is true.
But as soon as I change and something is false it's going to short circuit which we learned about previously
and return false.
All right so we know the greater than equal to less than sine.
We also have greater than or equal to so that if I do zero here and I click Run I get true.
Because it's saying hey is this greater than or equal to zero.
I can also do less than or equal to zero and here I get false because zero or one is not greater or
equal to zero.
But if I do zero here I'll get true here's another one.
What if I do this.
Exclamation mark equal.
This means in Python not equal to if I run this I get false and this is a little tricky.
What it's saying is hey is this not equal to this.
So it's the opposite of doing equals if these two things don't equal it's going to say true.
So if I do one here I'll get true because these two things do not equal.
So we've learned greater two or less than greater two equals equals or greater or greater or equal to.
We've learned about less than or equal to we've learned about not equal to but we've also learned about
and and or And finally there's one more I want to teach you and it's the not keyword.
I know I know it's it's a little it's a little much but it's not as hard as you think not is.
Well the opposite.
So if I do hear not true what do I get I get false and you see that not is also a function.
So it's a key word but also a function that we can use.
If I do not false again I just get the opposite.
What if I do this.
What if I do not want equals to one Why will I get here I get false because this expression evaluates
to true and then not just does the opposite.
So let's take a break here and work on a little bit of an exercise to make sure that we understand this.