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, I've actually seen them before and is a logical operator.
Or is a 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.
Equal to let's actually use them in 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 for 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 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, key word can 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 no.
It has to be a letter or underscore.
So when I do this, it's going to air because the interpreter is going to say, hey, I'm trying to
assign variable for 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 be.
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 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 hand hold you the entire way.
It's to develop the skills and 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 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 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 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.
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.
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 two one.
Well, 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.