Welcome back, everyone.
We're going to have two lectures on control flow and the first lecture.
We're talking about comparison and logical operators, which we can use to return back a Boolean.
Let's check it out.
All right.
Here I am inside of the Visual Studio code editor.
The first thing I want to talk about is comparison operator.
Just a quick tour of all of them.
So comparison operators allow you to compare two separate pieces of data or elements.
For example, we've actually already seen one.
Something like one is greater than two.
So this greater than symbol, that's the comparison.
Operator And we can actually print out the results.
So something like this one is greater than two or check if one is greater than two, really.
We'll go ahead and run that and we get back false.
So you should expect comparison operators to return back a brilliant either true or false.
And there is greater than.
Less than.
And then there's greater than or equal to.
So go ahead and check out this one.
And then there's less than or equal to so less than or equal to.
There is not equal, so not equal as exclamation mark equal.
So this tax is one not equal to two.
We would expect that statement to be true.
It's true that one is not equal to two.
And then for checking equality, it's just two equal sides.
Be careful because beginners often forget that it's to equal science and they try to do something like
this.
Remember, one equal sign is an assignment, so here you'd be kind of breaking Python by saying, OK,
one is actually equal to two now, so you want to be super careful of something like that.
I remember it's two equal science for comparison.
So let's go ahead and say something like two is equal to two.
Check this out.
And now we get back.
True, I remember this doesn't just have to be numbers, it can also be with strings.
For instance, I can say something like my record for an employee is, let's say, lowercase was a.
And then maybe I have some sort of match that I want to check out.
And it also happens to be Jose.
And then later on in my logic, I want to check if is the record equal to the match that I looked up
from somewhere else.
So that's the kind of thing you're going to be seeing a lot checking if, Hey, does this actually match
some sort of lookup?
All right.
So we can obviously do a comparison operators with variables.
Now, if you want to combine multiple comparison operations, that's where logical operators come into
play.
So for example, let's say I want to check both.
That one is greater than two and at two is less than three.
How would I actually do that?
Well, the main logical operators type that interest, so we make sure so we're now talking about logical
operators.
These are going to be key words like and and then or.
So how does this work?
I can say print is one greater than two and is to equal to two.
So for the and operator, you're going to need both of these statements to be true.
So we know one is not greater than two.
And then even if this is true, this one is false.
So since both are not true, we would expect this to be false.
We run this code and we get back false.
Let's go ahead and change this.
So we can say is three get greater than two and is to greater equal to two.
We'll go ahead and save that.
We expect this to be true because now both statements are true.
If I need either statement to be true, that's worthy or operator comes into play.
So this will return back a Boolean if either of these is true.
So, for example, I'm going to say again, one is greater than two or two equal to two.
So because one of these happens to be true, we should get back true here.
OK?
And that's basically it for the logical operators and comparison operators we work with throughout the
course.
There's a couple more things here, but we're going to introduce them later on.
The main idea being is you have this ability to check for equality of two equal sides or check for inequality
with exclamation mark, equal sign, and then you can combine multiple checks like that with and statements
or statements.
OK.
So what's going to do one last quick example here?
So we can get kind of a use case here.
So we're going to say user input is equal to.
And let's go ahead and say my password and we'll say stored.
Password.
Is my password, so you can imagine if someone is using our website and we were able to get back their
user input as my password and then we have their stored password as my password.
We can check for equality.
So then I could just print, Hey, is user input equal to the stored a password I have?
Now, obviously, you wouldn't store a password in plaintext, but you get the idea here.
This is the sort of check we can do with a comparison operation.
OK.
So what comparison operators and logical operators we can begin to learn about, if else, statements?
I'll see you there.