-: 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 list it out for you.
We have greater than,
less than,
equal to.
Let's actually use them in an example.
Is four 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
in math class.
If I do the opposite, is four less than five?
That makes sense.
That's true.
What about is four equal to five?
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 use to assign
to a variable, right?
And if you remember, I told you that
a variable in Python can't start 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 variable four, the value of five.
And well, 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.
Hmm, this is interesting and this is actually
quite an interesting reason.
So, 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 wanna 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 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 hand hold 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 run a bit 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, right, 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 sign.
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 two.
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 to or less than greater to
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 it's a little much
but it's not as hard as you think.
Not is the opposite.
So if I do here,
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 one equals to one.
What 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.