You can now use conditions to test some variables and test if something is true or false.
Now let's see what are the different comparison operators which will allow you to test different things.
Okay, so comparison operator.
For now we have only seen that one.
And we are going to discover all of them right now.
So first of all I will actually comment.
I'm going to keep the same file.
I will comment those lines.
So if you want to comment you just select.
You can right click for example and click on Toggle comment.
And you have the shortcut if you want to.
And I'm going to write some code here at the top.
So I will create a simple variable.
Let's name it a just for testing purposes.
And let's say A is equal to five.
And then let's do let's do a condition.
So if A is greater than three.
So same condition as before.
With this symbol we use the if and then a condition colon.
We go back to new line let's say print okay.
So let's run this we have.
Okay.
Because five is greater than three.
So this is the first operator is greater than three.
And actually I mentioned it before.
It's strictly greater than three.
So if I put three for example you will see that we don't have okay.
So three is not strictly greater than three okay.
For this to be true A needs to be at least at least four okay.
Then it's going to work.
You see now we have okay.
All right.
So with this angle bracket it means strictly greater than if you want to test if something is greater
or equal then you can add an equal sign okay.
Greater or equal.
In this case well four is still greater or equal than three.
But then three is also going to work because three is greater or equal than three okay.
So note this small difference.
It's actually quite important difference.
It's strictly greater or greater or equal then.
Now you can do the opposite.
So we have greater but you have lower.
So we have this symbol for greater and this symbol for lower.
And this one is actually going to be strictly lower.
So with three you see it's not going to work.
But if I put one one is strictly lower than three.
So it works.
And I also have lower or equal.
So it still works with one.
And if I put back three we have three is lower or equal than three.
So this condition is true okay.
So you already have four operators.
Now if we want to test the equality we can use equal equal sign.
This is going to test if A is equal to three okay.
So the only way this condition is true is if A is exactly three like this one you can see okay.
But if I put any other value like four doesn't work.
Two it doesn't work.
Well I think you get it.
So this will test the equality.
And note that it is super important to have two equal signs.
Okay.
This is a very common mistake.
You write a condition and you just write this.
Okay.
It looks like it makes sense and you can run it and well you will see that you get an error.
At least you get an error, because in some other languages, you might not even get an error.
And this will be very hard to debug.
So make sure that when you test the equality you have two equal signs okay?
One equal sign is already used to assign a value to a variable okay.
So two equal sign is the comparison operator for equality.
And now if you want to test the opposite.
So if you want to test if something is different than something else you can use exclamation mark equal.
In this case this is going to be true if a is different than three.
So any other value here you can see two is going to work because two is different than three.
Then if I put three This is false because well three is equal to three.
So it's not different.
All right.
So with this you have seen all of the operators.
So we have seen the greater the greater or equal.
So that one we have also seen the lower.
So strictly lower lower or equal we have seen the equal with two equal signs.
And then the different than with exclamation mark equal.
So those are the six operators that you can use in Python.
And on top of that you can actually combine different conditions.
Because here we just have one condition.
But maybe you want to test a combination of two different conditions or a combination of five conditions.
Then you can use the keywords.
So we have two keywords.
We have the keywords or like this.
And we have the keyword end.
And you can see we have syntax highlighting for those.
Let me make an example and you will understand.
So if I want to test that for example A is greater or equal than 20.
And I want to make sure that A is greater or equal than 20, but that A is also lower than 30.
So what I can do is to use the end keyword.
And I can put two conditions.
So a strictly lower than 30 for example.
Now let's run this.
You can see that we don't have.
Okay.
Now if I put uh 24 for example this is going to be okay.
So what happens in this case with the end keyword.
Well simply this is going to be true.
So we are only going to execute the if so the block of code here.
If that condition is true and that condition is true.
So both conditions need to be true so that we can print okay.
So in this case with 24 is 24 greater or equal than 20.
Yes.
And is 24 strictly lower than 30.
Yes.
So we print okay.
Now let's say I use 30.
Then we are not going to print okay.
Because this one is true.
So 30 is greater than 20, but then 30 is not strictly greater than 30.
So because we have true and false, the whole thing becomes false.
Okay.
So that's how you use the end keyword.
And we're going to see more examples of that as we progress throughout the course.
And now let's make an example with the Or.
So I'm going to test a different use case.
Let's say I have a is equal to ten or a is equal to 20.
So in this case I just want to test that a is either 10 or 20.
So if I put a ten here this is going to work.
This is going to be okay.
If I put a zero it's not going to work.
Okay.
So any other value than 10 or 20 is not going to work.
If I put 20 it's working.
So how does that work.
So with the all keyword you just need to have one condition to be true so that the whole thing will
be true.
Okay.
That's the difference with the in keyword.
So for example here with a is equal to 20 we check the first condition is a is equal to ten.
No this is false.
We go to.
The second one is a is equal to 20.
Yes.
So because this one is true the whole thing becomes true.
And we enter the if and you can also combine more than two conditions.
You can use any combination of all keyword and end keyword as you want.
Let's just add another or here A is equal to 30 okay.
So in this case it still works because this one is going to be false.
This one is going to be true.
This one is going to be false.
But because we are using or we just need one of them to be true okay.
So if I put 30 that's also going to be true okay.
Because this is false.
This is false and this one is true.
So the whole thing becomes true.
All right.
So now you have seen the six comparison operators and you have seen the keywords or and the keywords.
And so that you can combine different conditions.
Now let's do a bit more practice.