1
00:00:05,270 --> 00:00:06,430
Welcome back everyone.

2
00:00:06,710 --> 00:00:09,520
It's time to begin discussing the very basics of control flow.

3
00:00:09,560 --> 00:00:15,140
We're going to start by talking about comparison and logical operators comparison operators basically

4
00:00:15,140 --> 00:00:17,690
allow us to compare two different objects.

5
00:00:17,690 --> 00:00:22,670
So for numbers we can do things like compare if one is less than two or if two is greater than one.

6
00:00:22,780 --> 00:00:26,250
The other object types we can also just straight up compare or do the same thing.

7
00:00:26,480 --> 00:00:31,580
We can do this with an equals equal sign or we can compare if they're not the same thing with an exclamation

8
00:00:31,580 --> 00:00:32,590
mark will sign.

9
00:00:32,750 --> 00:00:36,440
So we're going to see some examples of those and we'll also expand this to do things like greater than

10
00:00:36,440 --> 00:00:38,820
or equal to or less than or equal to.

11
00:00:39,050 --> 00:00:44,090
Now for logical operators those are going to allow us to combine multiple comparison operators essentially

12
00:00:44,300 --> 00:00:46,370
chaining comparison operations.

13
00:00:46,370 --> 00:00:49,790
Let's get a better idea of all this by jumping over to the Adam text editor.

14
00:00:50,000 --> 00:00:52,030
OK here I am I thought py file.

15
00:00:52,060 --> 00:00:55,420
I want to start a couple of basic examples such as greater than or equal to.

16
00:00:55,690 --> 00:00:58,960
So we're going to say one greater than two.

17
00:00:59,240 --> 00:01:03,770
And I'm going to print the results of this so we can see it at our command line and then we'll kind

18
00:01:03,770 --> 00:01:04,960
of play around with this.

19
00:01:05,180 --> 00:01:11,030
So these are basic comparisons these comparison operators basically allowing us to compare two numbers

20
00:01:11,030 --> 00:01:12,660
together is one greater than two.

21
00:01:12,760 --> 00:01:15,320
And that's going to bring back the boolean false.

22
00:01:15,320 --> 00:01:16,440
So far so good.

23
00:01:16,500 --> 00:01:20,720
If I were to change this to something that would be true like is three greater than 2.

24
00:01:20,960 --> 00:01:22,220
I run that again that we get.

25
00:01:22,220 --> 00:01:22,780
True.

26
00:01:23,060 --> 00:01:28,370
So the basic comparison you can make are greater then or less then and then you can also do greater

27
00:01:28,370 --> 00:01:32,060
than or equal to or less than or equal to.

28
00:01:32,060 --> 00:01:34,520
So for example is three Lessner equal to 2.

29
00:01:34,520 --> 00:01:36,520
Well that's going to do false.

30
00:01:36,560 --> 00:01:37,820
If we run this.

31
00:01:37,820 --> 00:01:39,300
But let's change this to three.

32
00:01:39,530 --> 00:01:41,170
So it's three Lessner equal to three.

33
00:01:41,180 --> 00:01:43,240
Well that's true x 3 is equal to 3.

34
00:01:43,250 --> 00:01:45,190
So when you run that back you get true.

35
00:01:45,200 --> 00:01:51,370
So those are the main person operators for numbers really useful ones are when you compare for equality.

36
00:01:51,380 --> 00:01:55,810
So for example if I just wanted to compare for equality I used to equal signs.

37
00:01:55,910 --> 00:02:01,200
So two equal science performance comparison one equal signs here will actually give you an error because

38
00:02:01,200 --> 00:02:03,470
it's going to try to do a variable assignment.

39
00:02:03,650 --> 00:02:06,520
So remember for comparisons used to equal signs.

40
00:02:06,750 --> 00:02:09,120
So we're going to say three is equal to three.

41
00:02:09,120 --> 00:02:10,370
And when you read that you get back.

42
00:02:10,370 --> 00:02:11,020
True.

43
00:02:11,300 --> 00:02:16,910
And if you want to check Nonni quality you can say is three not equal to three which would give us false

44
00:02:16,910 --> 00:02:18,800
because 3 is equal to 3.

45
00:02:18,800 --> 00:02:20,810
So on a run that I get back false.

46
00:02:20,810 --> 00:02:24,220
Keep in mind this sort of equality doesn't just have to be for numbers.

47
00:02:24,230 --> 00:02:31,940
So for example let's say we have some sort of username and the username provided is adamant.

48
00:02:32,300 --> 00:02:38,630
And then we have our own check inside the system so I'll say our check is equal to admin as well.

49
00:02:38,660 --> 00:02:41,100
And notice I've capitalized am both.

50
00:02:41,360 --> 00:02:50,350
Well I could do is saying Prince is username equal to my check and that's something we're going to be

51
00:02:50,350 --> 00:02:53,440
doing a lot through our code checking for equality.

52
00:02:53,440 --> 00:02:55,470
And this ends up becoming true.

53
00:02:55,720 --> 00:03:00,550
So what's really useful about comparison operations is then you can check for things to be true or false

54
00:03:00,760 --> 00:03:03,220
and then run code based off those decisions.

55
00:03:03,220 --> 00:03:07,720
For example if a user name was admin and it equaled our check maybe we give this person more permissions

56
00:03:07,720 --> 00:03:09,870
for a web site that sort of thing.

57
00:03:09,900 --> 00:03:11,700
OK so those are comparison operators.

58
00:03:11,780 --> 00:03:16,500
But often you'll want to have multiple comparisons done at the same time.

59
00:03:16,540 --> 00:03:20,740
So for that you can use logical operators like and or or.

60
00:03:20,740 --> 00:03:22,360
So let's show you an example of that.

61
00:03:22,660 --> 00:03:24,650
Let's start with a simple comment.

62
00:03:24,670 --> 00:03:31,260
So I'm sort of a very simple example of is one equal to 1.

63
00:03:31,270 --> 00:03:33,730
So as you would expect when I run this I get back.

64
00:03:33,730 --> 00:03:34,360
True.

65
00:03:34,600 --> 00:03:42,200
Let's imagine I want to do another comparison maybe is one equal to 1 and is 2 less than three.

66
00:03:42,220 --> 00:03:44,890
So now when I run this I get back.

67
00:03:44,890 --> 00:03:48,390
True because one is equal to 1 and 2 is less than three.

68
00:03:48,460 --> 00:03:49,970
But let's make one of these.

69
00:03:50,230 --> 00:03:51,840
Not the case because.

70
00:03:51,880 --> 00:03:55,440
And it's going to need to check for all conditions to be true.

71
00:03:55,870 --> 00:03:59,800
So now when you run this you're going to get back false because one is not equal to two.

72
00:03:59,920 --> 00:04:02,980
So and requires that all conditions be true.

73
00:04:02,980 --> 00:04:08,040
If I changed this to or that requires at least one of these conditions to be true.

74
00:04:08,110 --> 00:04:12,190
So now when you run this you're going to get back true because even though the first one is false the

75
00:04:12,190 --> 00:04:13,840
second one happens to be true.

76
00:04:14,050 --> 00:04:15,650
So those are the AND and OR.

77
00:04:15,660 --> 00:04:21,790
And you can change these as high as you want so you can say is one to two or two equals a three or is

78
00:04:21,850 --> 00:04:23,170
four equal to four.

79
00:04:23,200 --> 00:04:24,140
And so on.

80
00:04:24,190 --> 00:04:25,960
So you can check those conditions for you.

81
00:04:26,140 --> 00:04:32,240
And often people like to wrap these separate conditions into parentheses just so it's easier to read.

82
00:04:32,770 --> 00:04:34,270
So you can see that as well there.

83
00:04:34,300 --> 00:04:37,180
So you kind of get an idea of each condition being checked.

84
00:04:37,180 --> 00:04:40,990
It's kind of up to you in the situation whether you want to use print sees it may make your code more

85
00:04:40,990 --> 00:04:42,830
readable so just keep that in mind.

86
00:04:42,940 --> 00:04:43,360
OK.

87
00:04:43,540 --> 00:04:51,370
So let's go into this festering example let's add in some permission variable and we're going to set

88
00:04:51,370 --> 00:04:54,250
this permission variable to a boolean false.

89
00:04:54,310 --> 00:04:55,690
So it's already a boolean.

90
00:04:55,780 --> 00:05:03,570
So I'm going to print is user name equal to check and permission.

91
00:05:03,580 --> 00:05:04,720
So no what's happening here.

92
00:05:04,720 --> 00:05:08,430
For permission I'm not actually providing some sort of comparison.

93
00:05:08,590 --> 00:05:14,140
I'm just providing a straight up boolean because remember comparison operators they always resolve to

94
00:05:14,140 --> 00:05:15,170
a boolean itself.

95
00:05:15,310 --> 00:05:20,120
So really and that or they're just looking for booleans does have to be a comparison operation.

96
00:05:20,410 --> 00:05:25,320
So when you run this think about what I should get adamant is equal to admen.

97
00:05:25,360 --> 00:05:27,270
But right now permission is false.

98
00:05:27,280 --> 00:05:32,130
So when I run this I get back false because currently there is no permission there.

99
00:05:32,170 --> 00:05:35,800
However let's change permission to be true.

100
00:05:35,920 --> 00:05:39,140
Save it and run it and then you get back.

101
00:05:39,160 --> 00:05:40,090
True.

102
00:05:40,090 --> 00:05:45,750
So this sort of clever choosing of your variable names allows your code to be super readable.

103
00:05:45,940 --> 00:05:53,320
So for instance I can say something like logged in is equal to true.

104
00:05:53,750 --> 00:05:55,410
And permission is equal to true.

105
00:05:55,670 --> 00:05:59,840
And later on in my code I could just read type and log in and permission.

106
00:05:59,840 --> 00:06:04,900
And it can even make it more readable by making this variable has permission and I'll change this to

107
00:06:04,900 --> 00:06:05,810
has permission.

108
00:06:05,830 --> 00:06:08,110
And now this basically reads like an English sentence.

109
00:06:08,170 --> 00:06:12,880
I'm asking Prince are they logged in and has permission.

110
00:06:12,950 --> 00:06:14,590
And in this case they are both true.

111
00:06:14,650 --> 00:06:17,700
So the result when I print this is true.

112
00:06:17,830 --> 00:06:23,170
So keep in mind these logical operators they don't necessarily need actual comparison operators they're

113
00:06:23,170 --> 00:06:28,630
just looking for booleans which at the end of the day is what a comparison operation such as username

114
00:06:28,720 --> 00:06:32,020
equals equals check is returning back to you.

115
00:06:32,380 --> 00:06:36,310
OK so that's the very basics of comparison operators and logical operators.

116
00:06:36,310 --> 00:06:41,590
Coming up next we're going to continue our discussion of control flow by talking about if elif and else

117
00:06:41,680 --> 00:06:42,450
statements.

118
00:06:42,550 --> 00:06:43,160
We'll see if they're.
