1
00:00:05,240 --> 00:00:06,200
Welcome back, everyone.

2
00:00:06,230 --> 00:00:09,630
We're going to have two lectures on control flow and the first lecture.

3
00:00:09,650 --> 00:00:15,050
We're talking about comparison and logical operators, which we can use to return back a Boolean.

4
00:00:15,260 --> 00:00:16,010
Let's check it out.

5
00:00:16,129 --> 00:00:16,370
All right.

6
00:00:16,400 --> 00:00:19,160
Here I am inside of the Visual Studio code editor.

7
00:00:19,460 --> 00:00:22,990
The first thing I want to talk about is comparison operator.

8
00:00:23,000 --> 00:00:25,400
Just a quick tour of all of them.

9
00:00:25,910 --> 00:00:30,920
So comparison operators allow you to compare two separate pieces of data or elements.

10
00:00:30,950 --> 00:00:32,930
For example, we've actually already seen one.

11
00:00:33,150 --> 00:00:35,090
Something like one is greater than two.

12
00:00:35,480 --> 00:00:38,400
So this greater than symbol, that's the comparison.

13
00:00:38,420 --> 00:00:40,890
Operator And we can actually print out the results.

14
00:00:40,890 --> 00:00:46,340
So something like this one is greater than two or check if one is greater than two, really.

15
00:00:46,790 --> 00:00:49,650
We'll go ahead and run that and we get back false.

16
00:00:49,730 --> 00:00:55,250
So you should expect comparison operators to return back a brilliant either true or false.

17
00:00:55,490 --> 00:00:57,590
And there is greater than.

18
00:00:58,850 --> 00:00:59,630
Less than.

19
00:01:00,200 --> 00:01:02,630
And then there's greater than or equal to.

20
00:01:03,380 --> 00:01:05,060
So go ahead and check out this one.

21
00:01:05,660 --> 00:01:09,700
And then there's less than or equal to so less than or equal to.

22
00:01:10,040 --> 00:01:15,320
There is not equal, so not equal as exclamation mark equal.

23
00:01:15,330 --> 00:01:18,380
So this tax is one not equal to two.

24
00:01:18,620 --> 00:01:20,630
We would expect that statement to be true.

25
00:01:21,020 --> 00:01:23,240
It's true that one is not equal to two.

26
00:01:23,570 --> 00:01:27,050
And then for checking equality, it's just two equal sides.

27
00:01:27,710 --> 00:01:32,030
Be careful because beginners often forget that it's to equal science and they try to do something like

28
00:01:32,030 --> 00:01:32,360
this.

29
00:01:32,750 --> 00:01:37,400
Remember, one equal sign is an assignment, so here you'd be kind of breaking Python by saying, OK,

30
00:01:37,400 --> 00:01:41,180
one is actually equal to two now, so you want to be super careful of something like that.

31
00:01:41,570 --> 00:01:44,270
I remember it's two equal science for comparison.

32
00:01:44,660 --> 00:01:47,450
So let's go ahead and say something like two is equal to two.

33
00:01:48,350 --> 00:01:49,100
Check this out.

34
00:01:49,310 --> 00:01:50,200
And now we get back.

35
00:01:50,210 --> 00:01:54,590
True, I remember this doesn't just have to be numbers, it can also be with strings.

36
00:01:54,860 --> 00:02:02,470
For instance, I can say something like my record for an employee is, let's say, lowercase was a.

37
00:02:02,810 --> 00:02:06,170
And then maybe I have some sort of match that I want to check out.

38
00:02:06,680 --> 00:02:08,199
And it also happens to be Jose.

39
00:02:08,210 --> 00:02:14,900
And then later on in my logic, I want to check if is the record equal to the match that I looked up

40
00:02:14,900 --> 00:02:16,100
from somewhere else.

41
00:02:16,400 --> 00:02:21,530
So that's the kind of thing you're going to be seeing a lot checking if, Hey, does this actually match

42
00:02:21,530 --> 00:02:22,400
some sort of lookup?

43
00:02:22,910 --> 00:02:23,230
All right.

44
00:02:23,240 --> 00:02:26,360
So we can obviously do a comparison operators with variables.

45
00:02:26,810 --> 00:02:32,870
Now, if you want to combine multiple comparison operations, that's where logical operators come into

46
00:02:32,870 --> 00:02:33,230
play.

47
00:02:33,770 --> 00:02:36,890
So for example, let's say I want to check both.

48
00:02:37,460 --> 00:02:40,490
That one is greater than two and at two is less than three.

49
00:02:40,520 --> 00:02:41,390
How would I actually do that?

50
00:02:41,810 --> 00:02:47,720
Well, the main logical operators type that interest, so we make sure so we're now talking about logical

51
00:02:47,720 --> 00:02:48,350
operators.

52
00:02:48,860 --> 00:02:52,610
These are going to be key words like and and then or.

53
00:02:53,780 --> 00:02:54,700
So how does this work?

54
00:02:54,710 --> 00:03:04,130
I can say print is one greater than two and is to equal to two.

55
00:03:04,550 --> 00:03:10,220
So for the and operator, you're going to need both of these statements to be true.

56
00:03:10,790 --> 00:03:13,340
So we know one is not greater than two.

57
00:03:13,730 --> 00:03:16,590
And then even if this is true, this one is false.

58
00:03:16,610 --> 00:03:19,280
So since both are not true, we would expect this to be false.

59
00:03:19,640 --> 00:03:22,580
We run this code and we get back false.

60
00:03:23,000 --> 00:03:24,230
Let's go ahead and change this.

61
00:03:24,230 --> 00:03:29,690
So we can say is three get greater than two and is to greater equal to two.

62
00:03:30,050 --> 00:03:31,210
We'll go ahead and save that.

63
00:03:31,220 --> 00:03:33,920
We expect this to be true because now both statements are true.

64
00:03:34,610 --> 00:03:39,470
If I need either statement to be true, that's worthy or operator comes into play.

65
00:03:39,560 --> 00:03:44,630
So this will return back a Boolean if either of these is true.

66
00:03:45,260 --> 00:03:51,470
So, for example, I'm going to say again, one is greater than two or two equal to two.

67
00:03:52,070 --> 00:03:55,760
So because one of these happens to be true, we should get back true here.

68
00:03:56,600 --> 00:03:56,930
OK?

69
00:03:57,020 --> 00:04:01,880
And that's basically it for the logical operators and comparison operators we work with throughout the

70
00:04:01,880 --> 00:04:02,360
course.

71
00:04:02,570 --> 00:04:05,720
There's a couple more things here, but we're going to introduce them later on.

72
00:04:05,990 --> 00:04:11,480
The main idea being is you have this ability to check for equality of two equal sides or check for inequality

73
00:04:11,480 --> 00:04:17,029
with exclamation mark, equal sign, and then you can combine multiple checks like that with and statements

74
00:04:17,480 --> 00:04:18,649
or statements.

75
00:04:19,160 --> 00:04:19,519
OK.

76
00:04:19,880 --> 00:04:22,520
So what's going to do one last quick example here?

77
00:04:22,670 --> 00:04:24,500
So we can get kind of a use case here.

78
00:04:24,920 --> 00:04:29,540
So we're going to say user input is equal to.

79
00:04:30,050 --> 00:04:35,690
And let's go ahead and say my password and we'll say stored.

80
00:04:37,290 --> 00:04:37,920
Password.

81
00:04:39,230 --> 00:04:45,350
Is my password, so you can imagine if someone is using our website and we were able to get back their

82
00:04:45,350 --> 00:04:50,580
user input as my password and then we have their stored password as my password.

83
00:04:50,600 --> 00:04:51,650
We can check for equality.

84
00:04:51,740 --> 00:04:58,190
So then I could just print, Hey, is user input equal to the stored a password I have?

85
00:04:58,970 --> 00:05:02,300
Now, obviously, you wouldn't store a password in plaintext, but you get the idea here.

86
00:05:02,630 --> 00:05:05,780
This is the sort of check we can do with a comparison operation.

87
00:05:06,560 --> 00:05:06,890
OK.

88
00:05:07,280 --> 00:05:12,170
So what comparison operators and logical operators we can begin to learn about, if else, statements?

89
00:05:12,470 --> 00:05:13,040
I'll see you there.

