WEBVTT

00:00.050 --> 00:05.030
You can now use conditions to test some variables and test if something is true or false.

00:05.060 --> 00:11.630
Now let's see what are the different comparison operators which will allow you to test different things.

00:11.660 --> 00:13.310
Okay, so comparison operator.

00:13.310 --> 00:15.440
For now we have only seen that one.

00:15.440 --> 00:18.470
And we are going to discover all of them right now.

00:18.560 --> 00:22.520
So first of all I will actually comment.

00:23.030 --> 00:24.260
I'm going to keep the same file.

00:24.260 --> 00:25.580
I will comment those lines.

00:25.580 --> 00:27.740
So if you want to comment you just select.

00:27.770 --> 00:32.120
You can right click for example and click on Toggle comment.

00:32.120 --> 00:33.980
And you have the shortcut if you want to.

00:34.310 --> 00:37.190
And I'm going to write some code here at the top.

00:37.190 --> 00:39.140
So I will create a simple variable.

00:39.140 --> 00:42.530
Let's name it a just for testing purposes.

00:42.740 --> 00:44.510
And let's say A is equal to five.

00:44.510 --> 00:46.940
And then let's do let's do a condition.

00:46.940 --> 00:51.350
So if A is greater than three.

00:51.920 --> 00:53.360
So same condition as before.

00:53.360 --> 00:58.460
With this symbol we use the if and then a condition colon.

00:58.460 --> 01:01.790
We go back to new line let's say print okay.

01:01.940 --> 01:05.180
So let's run this we have.

01:05.210 --> 01:05.600
Okay.

01:05.630 --> 01:07.280
Because five is greater than three.

01:07.280 --> 01:11.030
So this is the first operator is greater than three.

01:11.030 --> 01:12.740
And actually I mentioned it before.

01:12.740 --> 01:14.900
It's strictly greater than three.

01:14.900 --> 01:20.570
So if I put three for example you will see that we don't have okay.

01:20.570 --> 01:25.550
So three is not strictly greater than three okay.

01:25.580 --> 01:31.490
For this to be true A needs to be at least at least four okay.

01:31.490 --> 01:32.630
Then it's going to work.

01:32.660 --> 01:34.220
You see now we have okay.

01:34.250 --> 01:34.820
All right.

01:34.820 --> 01:42.500
So with this angle bracket it means strictly greater than if you want to test if something is greater

01:42.500 --> 01:45.470
or equal then you can add an equal sign okay.

01:45.470 --> 01:47.360
Greater or equal.

01:47.450 --> 01:51.050
In this case well four is still greater or equal than three.

01:51.080 --> 01:58.400
But then three is also going to work because three is greater or equal than three okay.

01:58.430 --> 02:00.350
So note this small difference.

02:00.380 --> 02:02.780
It's actually quite important difference.

02:03.260 --> 02:07.040
It's strictly greater or greater or equal then.

02:07.070 --> 02:08.510
Now you can do the opposite.

02:08.510 --> 02:11.120
So we have greater but you have lower.

02:11.120 --> 02:15.620
So we have this symbol for greater and this symbol for lower.

02:15.620 --> 02:18.560
And this one is actually going to be strictly lower.

02:18.560 --> 02:21.920
So with three you see it's not going to work.

02:21.980 --> 02:26.720
But if I put one one is strictly lower than three.

02:26.720 --> 02:27.740
So it works.

02:27.740 --> 02:30.530
And I also have lower or equal.

02:30.530 --> 02:32.450
So it still works with one.

02:32.570 --> 02:40.190
And if I put back three we have three is lower or equal than three.

02:40.220 --> 02:43.130
So this condition is true okay.

02:43.160 --> 02:45.560
So you already have four operators.

02:45.560 --> 02:51.230
Now if we want to test the equality we can use equal equal sign.

02:51.260 --> 02:55.430
This is going to test if A is equal to three okay.

02:55.460 --> 03:01.760
So the only way this condition is true is if A is exactly three like this one you can see okay.

03:01.760 --> 03:06.230
But if I put any other value like four doesn't work.

03:06.440 --> 03:08.060
Two it doesn't work.

03:08.060 --> 03:09.320
Well I think you get it.

03:09.320 --> 03:12.200
So this will test the equality.

03:12.350 --> 03:17.930
And note that it is super important to have two equal signs.

03:17.960 --> 03:18.320
Okay.

03:18.350 --> 03:20.090
This is a very common mistake.

03:20.120 --> 03:22.550
You write a condition and you just write this.

03:22.580 --> 03:23.120
Okay.

03:23.150 --> 03:29.300
It looks like it makes sense and you can run it and well you will see that you get an error.

03:29.330 --> 03:33.530
At least you get an error, because in some other languages, you might not even get an error.

03:33.530 --> 03:35.930
And this will be very hard to debug.

03:35.930 --> 03:40.100
So make sure that when you test the equality you have two equal signs okay?

03:40.130 --> 03:46.490
One equal sign is already used to assign a value to a variable okay.

03:46.520 --> 03:50.870
So two equal sign is the comparison operator for equality.

03:50.870 --> 03:52.550
And now if you want to test the opposite.

03:52.550 --> 04:00.230
So if you want to test if something is different than something else you can use exclamation mark equal.

04:00.230 --> 04:04.340
In this case this is going to be true if a is different than three.

04:04.340 --> 04:10.850
So any other value here you can see two is going to work because two is different than three.

04:10.940 --> 04:17.180
Then if I put three This is false because well three is equal to three.

04:17.180 --> 04:18.440
So it's not different.

04:18.470 --> 04:18.860
All right.

04:18.860 --> 04:21.410
So with this you have seen all of the operators.

04:21.410 --> 04:24.980
So we have seen the greater the greater or equal.

04:25.310 --> 04:28.220
So that one we have also seen the lower.

04:28.220 --> 04:34.670
So strictly lower lower or equal we have seen the equal with two equal signs.

04:34.670 --> 04:39.230
And then the different than with exclamation mark equal.

04:39.230 --> 04:43.610
So those are the six operators that you can use in Python.

04:44.840 --> 04:50.150
And on top of that you can actually combine different conditions.

04:50.180 --> 04:52.880
Because here we just have one condition.

04:52.880 --> 04:57.980
But maybe you want to test a combination of two different conditions or a combination of five conditions.

04:57.980 --> 04:59.390
Then you can use the keywords.

04:59.390 --> 05:00.470
So we have two keywords.

05:00.470 --> 05:02.690
We have the keywords or like this.

05:02.690 --> 05:04.820
And we have the keyword end.

05:04.850 --> 05:07.370
And you can see we have syntax highlighting for those.

05:07.370 --> 05:10.100
Let me make an example and you will understand.

05:10.100 --> 05:16.750
So if I want to test that for example A is greater or equal than 20.

05:16.750 --> 05:21.640
And I want to make sure that A is greater or equal than 20, but that A is also lower than 30.

05:21.670 --> 05:24.730
So what I can do is to use the end keyword.

05:24.730 --> 05:26.200
And I can put two conditions.

05:26.200 --> 05:29.230
So a strictly lower than 30 for example.

05:29.260 --> 05:30.550
Now let's run this.

05:31.450 --> 05:33.010
You can see that we don't have.

05:33.040 --> 05:33.550
Okay.

05:33.580 --> 05:39.160
Now if I put uh 24 for example this is going to be okay.

05:39.160 --> 05:43.180
So what happens in this case with the end keyword.

05:43.180 --> 05:46.570
Well simply this is going to be true.

05:46.570 --> 05:49.960
So we are only going to execute the if so the block of code here.

05:49.990 --> 05:54.850
If that condition is true and that condition is true.

05:54.850 --> 06:00.130
So both conditions need to be true so that we can print okay.

06:00.130 --> 06:04.900
So in this case with 24 is 24 greater or equal than 20.

06:04.900 --> 06:05.350
Yes.

06:05.350 --> 06:09.010
And is 24 strictly lower than 30.

06:09.040 --> 06:09.820
Yes.

06:09.820 --> 06:11.140
So we print okay.

06:11.170 --> 06:13.780
Now let's say I use 30.

06:13.900 --> 06:16.180
Then we are not going to print okay.

06:16.330 --> 06:17.650
Because this one is true.

06:17.650 --> 06:23.020
So 30 is greater than 20, but then 30 is not strictly greater than 30.

06:23.020 --> 06:28.630
So because we have true and false, the whole thing becomes false.

06:28.660 --> 06:29.020
Okay.

06:29.020 --> 06:30.730
So that's how you use the end keyword.

06:30.730 --> 06:34.870
And we're going to see more examples of that as we progress throughout the course.

06:35.260 --> 06:37.510
And now let's make an example with the Or.

06:37.540 --> 06:39.460
So I'm going to test a different use case.

06:39.580 --> 06:48.070
Let's say I have a is equal to ten or a is equal to 20.

06:48.100 --> 06:53.860
So in this case I just want to test that a is either 10 or 20.

06:53.890 --> 06:59.110
So if I put a ten here this is going to work.

06:59.110 --> 07:00.670
This is going to be okay.

07:00.940 --> 07:05.020
If I put a zero it's not going to work.

07:05.050 --> 07:05.650
Okay.

07:06.040 --> 07:09.160
So any other value than 10 or 20 is not going to work.

07:09.460 --> 07:10.900
If I put 20 it's working.

07:10.900 --> 07:12.670
So how does that work.

07:12.670 --> 07:18.580
So with the all keyword you just need to have one condition to be true so that the whole thing will

07:18.580 --> 07:19.090
be true.

07:19.120 --> 07:19.330
Okay.

07:19.360 --> 07:21.250
That's the difference with the in keyword.

07:21.310 --> 07:27.910
So for example here with a is equal to 20 we check the first condition is a is equal to ten.

07:27.940 --> 07:29.500
No this is false.

07:29.500 --> 07:30.040
We go to.

07:30.070 --> 07:32.170
The second one is a is equal to 20.

07:32.200 --> 07:32.800
Yes.

07:32.800 --> 07:35.830
So because this one is true the whole thing becomes true.

07:35.830 --> 07:39.790
And we enter the if and you can also combine more than two conditions.

07:40.000 --> 07:44.440
You can use any combination of all keyword and end keyword as you want.

07:44.470 --> 07:50.770
Let's just add another or here A is equal to 30 okay.

07:50.770 --> 07:55.300
So in this case it still works because this one is going to be false.

07:55.330 --> 07:56.980
This one is going to be true.

07:57.010 --> 07:58.390
This one is going to be false.

07:58.390 --> 08:03.070
But because we are using or we just need one of them to be true okay.

08:03.100 --> 08:07.900
So if I put 30 that's also going to be true okay.

08:07.900 --> 08:09.370
Because this is false.

08:09.400 --> 08:12.310
This is false and this one is true.

08:12.310 --> 08:13.990
So the whole thing becomes true.

08:14.440 --> 08:14.860
All right.

08:14.860 --> 08:19.750
So now you have seen the six comparison operators and you have seen the keywords or and the keywords.

08:19.750 --> 08:23.170
And so that you can combine different conditions.

08:23.170 --> 08:25.540
Now let's do a bit more practice.
